
usersfx
Users domain module for go-core-fx — registration and login by Telegram identity, user lookup, an Uber Fx module and a bun-backed repository.
Report Bug
·
Request Feature
Table of Contents
About The Project
usersfx is the users domain for the go-core-fx ecosystem. The root package holds the domain (User, Identity), the Service (RegisterOrLogin, Login, GetUser), the Repository port and the sentinel errors; Module() registers the Uber Fx module "users" with a named logger. Persistence ships as the nested bun module:
- Domain and port —
domain.go / errors.go / repository.go; the service never imports a storage driver
- Fx module —
Module() registers module "users" and decorates the injected *zap.Logger with that name
- bun repository — the
github.com/go-core-fx/usersfx/bun submodule maps users / user_identities tables (timestamps via bunfx.TimedModel), registers a user and identity in one transaction and handles the concurrent-registration race
- Strict lint config — a v2.14.0 golangci-lint configuration with a large strict-but-practical linter set
- Makefile + CI — formatting, linting, race-enabled tests, coverage, benchmarks, nested-module checks, and GitHub Actions workflows that run them
Features
- User registration and login by identity —
Service.RegisterOrLogin validates the identity, returns an existing user or creates one atomically; duplicate identities from concurrent requests resolve to the existing user
- User lookup —
Service.GetUser by user ID; all failures surface as wrapped sentinel errors (ErrValidationFailed, ErrNotFound, ErrIdentityExists)
- bun persistence submodule —
bun.NewRepository(db) implements the usersfx.Repository port over an injected *bun.DB; the adapter is bound to the port by the consuming application, not by this module
- Strict golangci-lint — the same golden config used across the go-core-fx modules
- CI pipeline — lint, race-enabled tests with coverage upload to Codecov, and benchmark tracking with alerting
Built With
(back to top)
Getting Started
Prerequisites
- Go 1.24.3 or newer for the root module (
go.mod requires go 1.24.3); the bun submodule requires go 1.26.1
- golangci-lint v2 (the config targets v2.14.0) for
make lint and make fmt
- GNU Make
Installation
go get github.com/go-core-fx/usersfx
Add the persistence submodule only if you need it:
go get github.com/go-core-fx/usersfx/bun
(back to top)
Usage
Module Wiring
Module() provides the *Service and decorates the logger; the application must also provide a usersfx.Repository (the port is bound to its adapter in the composition root):
fx.New(
logger.Module(),
bunfx.Module(),
usersfx.Module(),
// fx.Provide(...): *sql.DB, schema.Dialect, usersfx.Repository
)
Providing the Repository
The bun submodule implements the port over an injected *bun.DB:
import usersfx "github.com/go-core-fx/usersfx"
import usersbun "github.com/go-core-fx/usersfx/bun"
fx.Provide(func(db *bun.DB) usersfx.Repository {
return usersbun.NewRepository(db)
})
The consuming application owns the driver and dialect: it opens the *sql.DB, supplies the matching schema.Dialect to bunfx.New, and owns schema migrations for the users / user_identities tables.
The schema must enforce UNIQUE (provider, provider_id) on user_identities. RegisterOrLogin relies on the database rejecting a duplicate identity insert to resolve concurrent registrations for the same identity; without that constraint, two concurrent registrations can both commit and the same provider ID will map to two users.
(back to top)
Development
Make Targets
| Target |
Description |
make all |
Run all checks: fmt, lint, coverage, nested |
make version |
Display the current version (from git describe, defaults to 0.0.0) |
make fmt |
Run go generate ./..., then golangci-lint fmt |
make lint |
Run golangci-lint run --timeout=5m |
make test |
Run tests with race detector, shuffle and atomic coverage |
make coverage |
Produce coverage.out and an HTML report (coverage.html) |
make nested |
Build, vet, test and lint every nested module (auto-discovered go.mod directories below the root) |
make benchmark |
Run benchmarks into benchmark.txt |
make air |
Run the development server with air (TZ=UTC DEBUG=1) |
make deps |
Download module dependencies |
make gen |
Run go generate ./... |
make release |
Create a snapshot release with goreleaser |
make build |
Build the project into bin/ |
make clean |
Remove coverage output, benchmarks, dist/ and bin/ |
make help |
List all available targets |
Continuous Integration
The Go workflow runs on pushes to master and on pull requests (path-filtered to Go sources, go.mod/go.sum, the lint config and the workflows themselves):
- Lint — golangci-lint with the repository config
- Test — race-enabled, shuffled tests with coverage uploaded to Codecov
- Benchmark — runs
go test -bench, keeps history in the Actions cache, uploads results when benchmarks exist and fails the job on a performance alert
- E2E Test — present but disabled (
if: false)
The Nested modules workflow runs make nested on the same triggers: root patterns like ./... stop at a nested module's boundary, so each module (e.g. bun) gets its own build, vet, test and lint pass. Discovery lives in the Makefile — any directory with its own go.mod is picked up automatically.
A second workflow marks issues and pull requests stale after 7 days of inactivity and closes them 7 days later.
(back to top)
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature)
- Commit your Changes (
git commit -m 'Add some AmazingFeature')
- Push to the Branch (
git push origin feature/AmazingFeature)
- Open a Pull Request
Please run make all before opening the pull request — it formats, lints and tests the change.
(back to top)
License
Distributed under the Apache License 2.0. See LICENSE for more information.
(back to top)
Acknowledgments
(back to top)