fx-libs
This project is a Multi-Module Go 1.18 Workspace that contains mostly FX modules for our team's microservices.
If you've never used FX, we highly recommend it. Preslav Mihaylov does a brilliant job in explaining what it is, why you'd want to use it, and the trade-offs teams should consider before adopting it.
Modules
As much as possible, we try to keep these modules independent of each other.
Sometimes, when they become glued together (as is the case in
gin/newrelic/zerolog
), it's convenient to reference
a shared configuration struct.
Module | Description | Dependent on other modules |
---|---|---|
fx/genqlient |
GraphQL client built on genqlient | NO |
fx/gin |
Gin HTTP server | NO |
fx/gin/newrelic |
Gin middleware for New Relic instrumentation | NO |
fx/gin/newrelic/zerolog |
Gin middleware for New Relic "Logs in Context" | YES |
fx/http/client |
Fine-tuned HTTP client | NO |
fx/http/client/newrelic |
New Relic-instrumented HTTP client | NO |
fx/newrelic |
Configures a New Relic Go Agent | NO |
fx/zerolog |
Configures a New Relic Zerolog logger | YES |
gqlgen |
Interceptors for gqlgen | NO |
Installation
You can install modules individually, but this can lead to large go.mod
files.
Instead, we recommend you install a recipe.
For example:
go get -v github.com/kevinmichaelchen/fx-libs/fx/recipes/standard
Updating dependencies
If you don't want to use recipes, you can update modules together easily:
go list all | grep github.com/kevinmichaelchen/fx-libs | xargs go get -v
Usage
Check out the example project, which you can run with
export NEW_RELIC_KEY=foobar
make example
In main.go
:
package main
import (
"github.com/kevinmichaelchen/fx-libs/gin"
"github.com/kevinmichaelchen/fx-libs/recipes/standard"
"go.uber.org/fx"
)
var Module = fx.Options(
standard.Module,
// Gin HTTP handler
gin.CreateModule(gin.ModuleOptions{
Invocations: []any{
// Add a registration function here to register your business logic
// layer (often called the "Service layer" or "Use case layer") to
// your GraphQL Handler.
},
}),
)
func main() {
a := fx.New(
Module,
)
a.Run()
}
Contributing
Releasing new versions
Run the tag
script
./tag.sh
which will prompt you to pick a SemVer change type:
- major
- minor
- patch
It will generate a Git tag for the repository root, as well as for all descendant submodules.
go work sync
Because this project uses a Go 1.18 Workspace, when working here, you almost
never want to use go mod
, as it's unable to reason about cross-module
dependencies.
Instead, go work
is you're friend. When you want to "download or tidy your
dependencies," simply run:
go work sync