Skip to content

gRPC Gateway project template mainly based on the Standard Project Layout

License

Notifications You must be signed in to change notification settings

vadimalekseev/go-grpc-gateway-template

Repository files navigation

go-grpc-gateway-template

  • Go Report Card

  • Go Doc

  • Go Reference

  • Release

Goal

Bringing practices together when building yet another web service.

About template

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).

Requirements

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.

First steps

Third party dependencies

To download third party dependencies (e.g. buf, proto-gen-go, goose, Swagger UI) run make deps.

Build

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.

Run

Use make run to run the application with default config.

Lint before commit

Run make lint. It will check *.proto files with buf and *.go files with golangci-lint

Set up dependent services

Run docker compose up to run PostgreSQL.

Run tests

# 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

Create migration

GOOSE_DRIVER=postgres GOOSE_DBSTRING=$DSN make migration

The new migration will be added to the migration folder. Do not forget to rename it.

Apply migrations

GOOSE_DRIVER=postgres GOOSE_DBSTRING=$DSN make migrate

Create new service

  • 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.

After fork

  1. Rename the name of the module in the go.mod file;
  2. Replace the default go_package_prefix with the new module name in buf.gen.yaml file;
  3. Fix badges references in README.md file;
  4. Change author in LICENSE file;

About

gRPC Gateway project template mainly based on the Standard Project Layout

Resources

License

Stars

Watchers

Forks

Packages

No packages published