The bazel documentation isn't entirely clear at this point, so I'm doing a short writeup of my experience here.
I essentially want to bazel-ise the Google Cloud Enpoints with Go Tutorial. I'm working in a private repo, so I won't be sharing links to my repo.
The first issue I came across was how to handle external dependencies. In the sample app.go has a dependency on "github.com/gorilla/mux".
Its not too difficult to handle external dependencies. In your WORKSPACE file at the root of your repo, you'll want to include:
load("@io_bazel_rules_go//go:def.bzl", "new_go_repository") new_go_repository( name = "com_github_gorilla_mux", importpath = "github.com/gorilla/mux", commit = "392c28fe23e1c45ddba891b0320b3b5df220beea", )I chose the commit hash of the most recent tagged version. You can specify tag here instead of commit if you prefer.
Next up, in your BUILD file that sits next to your code, you'll need to actually add a dependency to mux. Below is the entirety of my BUILD file, as it currently stands.
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "new_go_repository") go_binary( name = "api", srcs = ["app.go"], deps = ["@com_github_gorilla_mux//:go_default_library"] )
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.