This is the home for all new Golang code for all magma deployment targets.
Goals:
- Single go.mod defines all dependencies in one place and keeps versions in sync.
- Code can easily be shared with natual package paths that match file paths. No replace directives necessary in go.mod.
- Make it easy to find shared libs/patterns for use across magma targets.
- Other projects can easily import github.com/magma/magma/src/go code for use in derivative works.
Notes:
- The go.mod is placed at $MAGMA_ROOT/src/go to avoid name collisions with existing Go directories.
- We eventually want a canonical golang import path of magmacore.org/magma
When updating or adding a new dependency, run
bazel run //:gazelle -- update-repos -from_file=src/go/go.mod -to_macro=bazel/go_repositories.bzl%go_repositories
To generate BUILD.bazel files, run
bazel run //:gazelle
To run all the tests, run
bazel test //src/go/...
Only pull in dependencies when they are worth their weight in tech debt. Strongly review libraries before adding as a dependency along the following considerations:
- Does the dependency have a license compatible with BSD-3?
- How large is the dependency and its transitive dependencies? Weigh the total increase in go.sum against the provided functionality.
- Does the dependency have good test coverage and is it well maintained?
- What alternatives were considered?
Add the considerations in this README when adding the dependency to go.mod.
Google/Go authors BSD-3 license.
A large/heavy dependency, but provides a solid, well-tested, and production- hardened IDL. Good semantics for forwards/backwards compatibility and highly performant. Front-runner for de facto standard IDL/serdes library in modern software engineering projects.
Considered alternatives: Thrift, Swagger, JSON Schema.
Apache License 2.0
A large/heavy dependency that provides both RPC service IDL and base client/server implementation. Tightly coupled with protobuf.
Considered alternatives: Thrift, Swagger, JSON-RPC
MIT license.
Medium weight, pulls in a few transitive dependencies, but has a large overlap with testify. Provides scoped/named loggers and parameterized logging while achieving better performance than other libraries proven via benchmarks.
Very well tested: 98% code coverage; performance benchmarks included in CI
Considered alternatives: built-in log, glog, klog
MIT license.
Lightweight, for test purposes only. Good test coverage and widely adopted.
Downside is main usage eschews compile-time type checking in favor of runtime reflection-based equality checking.
Considered alternatives: regular Golang code
Apache License 2.0
Lightweight test tool to codegen verifiable mocks from interfaces. Generated EXPECT() functions are type-defined, which engages compile-time checking. Strict call count and ordering expectation. These explicit requirements make GoMock superior to mockery.
Considered alternatives: mockery, hand-coded mock implementations
TBD -- manual DI or library e.g. Uber dig/fx
In most cases, we will want to abstract dependencies via a clean interface package. In this context, "clean" means the interface package is defined entirely with Golang built-ins and other clean magma interface packages. i.e. there are no 3rd party library dependencies, except for test helpers (e.g. gomock).