Bringing practices together when building yet another web service.
Project contains echo server with PostgreSQL integration. It supports gRPC and HTTP transports
using gRPC to JSON proxy generator.
Proto files generated with buf.
Also, the template provides
/health
(liveness probe)
and /metrics
(using Prometheus).
The project has been tested on Go 1.17. It uses some new features such as go install
, go:embed
(for third party dependencies like Swagger UI).
Other binary dependencies will be downloaded to the bin
folder.
To download third party dependencies (e.g. buf, proto-gen-go, goose, Swagger UI) run make deps
.
Use make build
to build the application.
It will download the Swagger UI if it does not exist
and compile the application into the bin
folder.
Use make run
to run the application with default config.
Run make lint
. It will check *.proto files with buf and *.go files with golangci-lint
Run docker compose up
to run PostgreSQL.
# Run unit tests
make test
# Run integration tests
# Paste your connection string.
# If you ran "docker compose up", you can copy-paste the code below.
export DSN="user=postgres password=postgres database=postgres sslmode=disable"
# run migrations
GOOSE_DRIVER=postgres GOOSE_DBSTRING=$DSN make migrate
# run integration tests
make test-integration
GOOSE_DRIVER=postgres GOOSE_DBSTRING=$DSN make migration
The new migration will be added to the migration folder. Do not forget to rename it.
GOOSE_DRIVER=postgres GOOSE_DBSTRING=$DSN make migrate
-
Add a new service to
proto/echo/v1/echo.proto
file or add a new proto file to the proto folder; -
Then run
make
- it will generate new *.pb.go files in the pkg folder.; See generate code with buf for more information.
- Rename the name of the module in the
go.mod
file; - Replace the default
go_package_prefix
with the new module name in buf.gen.yaml file; - Fix badges references in README.md file;
- Change author in LICENSE file;