Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wingkwong/go-grpc-boilerplate
A gRPC microservice boilerplate written in Go
https://github.com/wingkwong/go-grpc-boilerplate
boilerplate go golang grpc microservice
Last synced: about 2 months ago
JSON representation
A gRPC microservice boilerplate written in Go
- Host: GitHub
- URL: https://github.com/wingkwong/go-grpc-boilerplate
- Owner: wingkwong
- License: mit
- Created: 2021-10-01T13:45:08.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T20:26:27.000Z (about 1 year ago)
- Last Synced: 2024-11-15T07:17:24.477Z (3 months ago)
- Topics: boilerplate, go, golang, grpc, microservice
- Language: Go
- Homepage:
- Size: 60.9 MB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-grpc-boilerplate
A gRPC microservice boilerplate written in Go## Installation
Install [protoc](http://google.github.io/proto-lens/installing-protoc.html)
```bash
PROTOC_ZIP=protoc-3.14.0-osx-x86_64.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
sudo unzip -o $PROTOC_ZIP -d /usr/local 'include/*'
rm -f $PROTOC_ZIP
```## MySQL
```
brew install mysql
``````
mysql.server start
```### Optional
Install ``vscode-proto3`` in Visual Studio Code
## Project Layout
Refer to [golang-standards/project-layout](https://github.com/golang-standards/project-layout)
## Run protobuf Compiler
```bash
protoc --proto_path=api/proto/v1 --proto_path=third_party --go_out=plugins=grpc:pkg/api/v1 foo-service.proto
protoc --proto_path=api/proto/v1 --proto_path=third_party --grpc-gateway_out=logtostderr=true:pkg/api/v1 foo-service.proto
protoc --proto_path=api/proto/v1 --proto_path=third_party --swagger_out=logtostderr=true:api/swagger/v1 foo-service.proto
```## Run gRPC Server with HTTP/REST gateway
```
cd cmd/server
go build .
./server -grpc-port=9090 -http-port=8080 -db-host=:3306 -db-user= -db-password= -db-schema= -log-level=-1
```### Logging Level
- -1 : DebugLevel logs are typically voluminous, and are usually disabled in production.
- 0: InfoLevel is the default logging priority.
- 1: WarnLevel logs are more important than Info, but don't need individual human review.
- 2: ErrorLevel logs are high-priority. If an application is running smoothly, it shouldn't generate any error-level logs.
- 3: DPanicLevel logs are particularly important errors. In development the logger panics after writing the message.
- 4: PanicLevel logs a message, then panics.
- 5: FatalLevel logs a message, then calls os.Exit(1).## Run gRPC Client
```
cd cmd/client-grpc
go build .
./client-grpc -server=localhost:9090
```## Run REST Client
```
cd cmd/client-rest
go build .
./client-rest -server=http://localhost:8080
```## Run test
```
cd pkg/service/v1
go test
```