Skip to content

Latest commit

 

History

History

grpc-service

GPRC Service

Opinionated GRPC service with embedded GRPC Gateway for REST HTTP.

  • grpc code generated with Buf CLI
  • postgres for SQL database
  • sql migrations with Goose
  • generated sql methods with sqlc with pgx

Install required tools

go install \
    github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \
    github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
    google.golang.org/protobuf/cmd/protoc-gen-go \
    google.golang.org/grpc/cmd/protoc-gen-go-grpc \
    github.com/sqlc-dev/sqlc/cmd/sqlc \
    github.com/pressly/goose/v3/cmd/goose

Install Buf CLI

Generate gprc code and swagger json

buf generate

Generate db methods from sql queries

sqlc generate

Run service locally

go run . serve

Adding SQL migrations

goose -dir db/migrations create DESCRIPTIVE_FILENAME sql

GRPC UI to test GRPC endpoints (like a Postman for HTTP)