go-grpc-gateway-template

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2021 License: MIT

README

go-grpc-gateway-template

  • Go Report Card

  • Go Doc

  • Go Reference

  • Release

Goal

Bringing practices together when building yet another web service.

Example usage

Project contains echo server with PostgreSQL integration. It supports gRPC and HTTP transports using gRPC to JSON proxy generator. Proto files generated with buf.

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 project

Run make build. It will download Swagger UI if it does not exist and build echoapi/main.go file.

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;

Directories

Path Synopsis
cmd
internal
pkg
echo/v1
Package echov1 is a reverse proxy.
Package echov1 is a reverse proxy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL