No description
  • Go 93.5%
  • Shell 6.4%
  • Nix 0.1%
Find a file Use this template
hayshin 48d973d9de
All checks were successful
CI / format (push) Successful in 6s
CI / vet (push) Successful in 3m25s
CI / build (push) Successful in 3m19s
CI / test (push) Successful in 3m38s
CI / links (push) Has been skipped
CI / ci (push) Successful in 0s
refactor: adopt shared go-pkg service tooling (#1)
- migrate service imports and dependencies to go-pkg v0.2 layout
- consume shared devenv, Docker Compose, and reusable Forgejo CI tooling
- document shared development and test commands

Co-authored-by: Dauren Baimurza <dauren.baimurza@frhc.group>
Co-authored-by: hayshin <hayshinbj@gmail.com>
Reviewed-on: #1
2026-07-19 10:43:19 +05:00
.forgejo/workflows refactor: adopt shared go-pkg service tooling (#1) 2026-07-19 10:43:19 +05:00
api/proto/item/v1 feat: initial go micro template 2026-07-10 13:22:34 +05:00
cmd refactor: adopt shared go-pkg service tooling (#1) 2026-07-19 10:43:19 +05:00
deploy feat: initial go micro template 2026-07-10 13:22:34 +05:00
docs feat: initial go micro template 2026-07-10 13:22:34 +05:00
internal refactor: adopt shared go-pkg service tooling (#1) 2026-07-19 10:43:19 +05:00
pkg feat: initial go micro template 2026-07-10 13:22:34 +05:00
scripts feat: initial go micro template 2026-07-10 13:22:34 +05:00
tests refactor: adopt shared go-pkg service tooling (#1) 2026-07-19 10:43:19 +05:00
.editorconfig feat: initial go micro template 2026-07-10 13:22:34 +05:00
.gitignore feat: initial go micro template 2026-07-10 13:22:34 +05:00
buf.gen.yaml feat: initial go micro template 2026-07-10 13:22:34 +05:00
buf.yaml feat: initial go micro template 2026-07-10 13:22:34 +05:00
devenv.lock refactor: adopt shared go-pkg service tooling (#1) 2026-07-19 10:43:19 +05:00
devenv.nix refactor: adopt shared go-pkg service tooling (#1) 2026-07-19 10:43:19 +05:00
devenv.yaml refactor: adopt shared go-pkg service tooling (#1) 2026-07-19 10:43:19 +05:00
docker-compose.yaml refactor: adopt shared go-pkg service tooling (#1) 2026-07-19 10:43:19 +05:00
example.env feat: initial go micro template 2026-07-10 13:22:34 +05:00
go.mod refactor: adopt shared go-pkg service tooling (#1) 2026-07-19 10:43:19 +05:00
go.sum refactor: adopt shared go-pkg service tooling (#1) 2026-07-19 10:43:19 +05:00
README.md refactor: adopt shared go-pkg service tooling (#1) 2026-07-19 10:43:19 +05:00
sqlc.yaml feat: initial go micro template 2026-07-10 13:22:34 +05:00

go-micro

A reference microservice template built on the shared platform package git.hayshin.dev/platform/go-pkg. It ships a complete Item CRUD gRPC service with a transactional outbox → NATS JetStream event flow, so you can clone it, rename the sample domain, and start building.

What it demonstrates:

  • gRPC API (item.v1.ItemService) with the platform interceptor stack (grpcstack.CoreConfig): error mapping, metadata, tracing, metrics, logging, health, and reflection.
  • Layered architecture: transport → service → repository → entity.
  • PostgreSQL access via sqlc-generated queries and explicit transactions (pgtx.Manager.DoTx).
  • Atomic domain writes + event emission through the transactional outbox (pgoutbox), relayed to NATS JetStream (natsoutbox).
  • Config from the environment (config.Load), client lifecycle (clients.NewList), a telemetry server with health probes, and goose migrations.

Layout

.
├── api/proto/item/v1/         # protobuf source (item + item_api)
├── pkg/grpcapi/item/v1/       # generated gRPC/protobuf Go (importable)
├── cmd/
│   ├── server/                # service entrypoint (srv.Run → app.Run)
│   └── migrator/              # migrations entrypoint (up|down|status)
├── internal/
│   ├── api/grpc/itemapiv1/    # gRPC controller + proto<->entity converters
│   ├── app/                   # config, wiring (app.go), modules/, migrator
│   ├── db/                    # sqlc queries + schema
│   ├── entity/                # domain models
│   ├── gen/pgqueries/         # generated sqlc code
│   ├── migrations/pg/         # goose migrations
│   ├── repository/            # itemrepo port + pg impl + mocks
│   └── service/item/          # business logic
├── tests/                     # integration suite (build tag: integration)
├── scripts/rename.sh          # rebrand the sample domain
├── example.env                # sample configuration
└── devenv.nix                 # service identity override

Quick start

This module uses the released git.hayshin.dev/platform/go-pkg Go module. For private module access, configure Go once if needed:

go env -w GOPRIVATE=git.hayshin.dev GONOSUMDB=git.hayshin.dev

Then:

devenv shell             # enter the dev environment (or prefix: devenv shell <cmd>)
compose-up               # start postgres + nats
migrate up               # apply migrations (service + outbox)
run                      # start the gRPC server on :50051

# In another shell:
grpcurl                  # calls ItemService.CreateItem via reflection

Run help inside the dev shell for the full command list (gen, proto, sqlc, mocks, lint, test, test-integration, migrate, compose-up, rename, ...). devenv.yaml imports the reusable microservice profile from the remote go-pkg input; local devenv.nix only overrides service identity. docker-compose.yaml extends services from the shared go-pkg Docker Compose file. compose-up/compose-down resolve that file from the Go module cache via go list and export GO_PKG_DOCKER_COMPOSE for Compose.

Testing

test-unit          # unit tests (no infrastructure)
test-integration   # starts shared go-pkg Docker deps, then runs integration tests
test               # unit and integration tests

The integration suite uses git.hayshin.dev/platform/go-pkg/runtime/integrationtest to start PostgreSQL and NATS from the released go-pkg module, then starts the service in-process and exercises the full CRUD surface plus the outbox event flow.

Code generation

After editing .proto or .sql files, regenerate:

gen        # proto (buf) + sqlc + mocks (go generate)

Rename the sample domain

Replace the item sample with your own aggregate:

./scripts/rename.sh --domain order
./scripts/rename.sh --domain order --module git.example.com/team/orders

It rewrites identifiers and paths, then regenerates code. Review the diff and run go mod tidy && go build ./....

Configuration

All configuration is read from environment variables — see example.env. Key groups: GRPC_*, TELEMETRY_*, PG_*, NATS_*.