Skip to main content

Managing Go Dependencies

Third party go libraries are managed by go mod and bazel mod.

Add / Remove 3rd party libraries​

  1. Add / Remove import in .go files
  2. run 'go mod tidy' in /go directory
  • This command will add or remove 3rd party libraries to go.mod file based on the "import" of all the .go files in /go directory
  • go.sum is the checksum of go.mod file
  1. run 'bazel mod tidy' in root directory if needed
  • After running 'go mod tidy', if the go.mod file is updated (some dependencies are changed), the command will prompt you to to run 'bazel mod tidy'
  • bazel mod tidy will update MODULE.bazel file in root directory
  1. commit the updated go.mod, go.sum, MODULE.bazel files

Add libraries that are not imported by any .go file​

For the libraries that are needed by 1) go tools in /tools directory, or 2) go code generated by protobuf compiler, but are not imported by any .go files in /go directory, you have to import the library to go/tools.go file.

Import the libraries with _ alias in go/tools.go file (there are already some examples in the file), and then follow the 1-4 steps above to update go.mod, go.sum, MODULE.bazel files