Skip to content

Nikita-Filonov/sample_go_grpc_server

Repository files navigation

Go GRPC server

Sample of GRPC server written on go

Setup protobuf

You can skip this section if you do not want to change existing protobuf

  1. Install protobuf on your system
  2. Install protoc-gen-go-grpc for go go install google.golang.org/protobuf/cmd/protoc-gen-go@latest. This is used to generate client/server code for golang

Generate client, server golang code with command:

protoc --go_out=./gen --go_opt=paths=source_relative --go-grpc_out=./gen --go-grpc_opt=paths=source_relative ./proto/my_service.proto

Setup project

You have to install go and sqlite3

Clone the project and install go packages

git clone https://github.com/Nikita-Filonov/sample_go_grpc_server`
cd ./sample_go_grpc_server
go mod download

Apply migrations

go install github.com/rubenv/sql-migrate/...@latest
sql-migrate up -config=./infrastructure/config.yml

Finally run the server

go run main.go

Setup project in docker

You can run project inside docker, make sure you have docker installed

git clone https://github.com/Nikita-Filonov/sample_go_grpc_server
cd ./sample_go_grpc_server
docker build . -t sample_go_grpc_server
docker run -p 8000:8000 sample_go_grpc_server

Apply migrations

docker ps
docker exec -it <container-id> sh
sql-migrate up -config=./infrastructure/config.yml
exit