This is a Go Microservice Playground project, implementing User Management Services with REST, gRPC and GraphQL APIs, PostgreSQL storage, and Kafka notifications.
Provides:
- HTTP API
- POST /api/v1/user
- GET /api/v1/user/:id
- GET /api/v1/users?page=1&limit=10&country=GB
- PUT /api/v1/user/:id with JSON body
- DELETE /api/v1/user/:id
- gRPC/GraphQL API:
- Create
- User
- Users
- Update
- Delete
- User change notifications via Kafka
- Health check
- GET /health
- Go 1.23.6
- GNU Make 4.3
- Docker 27.5.1
- jq 1.6
- graphviz 2.43.0
- PostgreSQL - for storing user data
- Apache Kafka - for notifying other services of user changes
- User HTTP/gRPC services handle user management requests
- User data stored in PostgreSQL
- Notifier notifies other services of user changes via Kafka
- Services code
- Public and internal contracts
- HTTP server, router and handlers
- gRPC server, router and handlers
- Domain - user domain logic
- Storage - database adapter
- Notifier - user changes notifier
- Go-otelw for telemetry
- Viper and Viperx for configuration
- Gin for HTTP routing
- Pgx and Pq PostgreSQL drivers for storage and notifications
- Kafka client for publishing notifications
go-userv
├── cmd
│ └── user-*
│ ├── config.go
│ ├── config.yml
│ ├── Dockerfile
│ └── main.go
├── db
│ └── postgres
│ ├── migrations
│ └── init.sql
├── contract
│ ├── dto
│ │ └── *.go
│ ├── graphql
│ │ └── *.graphql
│ └── proto
│ └── *.proto, *.pb.go
├── internal
│ ├── contract
│ │ ├── domain
│ │ ├── server
│ │ └── storage
│ ├── domain
│ ├── notifier
│ ├── router
│ │ ├── grpc
│ │ └── http
│ ├── server
│ │ ├── grpc
│ │ └── http
│ └── storage
│ └── postgres
├── make
│ └── *.mk
├── test
│ └── integration
├── docker-compose.yml
├── go.mod
├── go.sum
├── Makefile
└── README.md
The service build system is constructed with GNU Make and Docker BuildKit.
-
Display help
make help
-
All - install, lint, test, coverage, build, run
make all
-
Install project
make install
- This installs required tools and Git hooks.
-
Lint
make lint
- Currently limited to Go files only, mocks_*.go excluded.
-
Test
make test
- Runs:
- Router unit tests
- REST, gRPC, GraphQL integration tests
- Generates test results in JUnit XML Format, ready to be consumed by CI/CD pipelines, e.g. Jenkins, GitLab CI/CD, CircleCI, Azure DevOps, etc.
- Runs:
-
Make coverage report
make coverage
- This generates a coverage report in HTML format, try to open it in a browser
-
Generate dependency graph
make deps
- Generates dependency graph in docs/dep-..
-
Build docker images
make build
-
Run all
make run
- Runs User Service and 3rd party dependency services in Docker containers
-
All Logs
docker compose logs -f
-
Selective Logs
docker compose logs -f user-rest
docker compose logs -f user-notifier kafka
docker compose logs -f user-grpc postgres
-
Start dependency services only
make doco-up-dependencies
- Now you can run and debug the
user-*
service in vscode
- Now you can run and debug the
-
Kafka consumer In 2nd terminal
./test/scripts/kafka-consumer.sh
- This allows to observe user changes
-
Create, list, get, update, delete users In 3rd terminal:
-
Stop
make stop
- Stops all running services
-
Clean
make clean
- Stops running services, removes all containers, mocks and generated folders
-
Remove docker volume
docker volume rm go-userv_user-data
- Removes the docker volume with user data in PostgreSQL database
-
Health check
./scripts/health-check.sh
- Returns health status of the User Service
- More unit tests
- API annotaions and documentation
- Telemetry