Practicing GRPC Server using Golang as Programming Language, PostgreSQL as Database
Your project directory structure should look like this
+ your_gopath/
|
+--+ src/github.com/moemoe89
| |
| +--+ go-grpc-server-tisa/
| |
| +--+ main.go
| + api/
| + routers/
| + ... any other source code
|
+--+ bin/
| |
| +-- ... executable file
|
+--+ pkg/
|
+-- ... all dependency_library required
- Setup Golang https://golang.org/
- Setup PostgreSQL https://www.postgresql.org/
- Setup BloomRPC https://github.com/uw-labs/bloomrpc/
- Under
$GOPATH
, do the following command :
$ mkdir -p src/github.com/moemoe89
$ cd src/github.com/moemoe89
$ git clone <url>
$ mv <cloned directory> go-grpc-server-tisa
- Copy
config-sample.json
toconfig.json
and changes the value based on your configurations. - Create PostgreSQL database for example named
simple_api
and do migration withGoose
https://bitbucket.org/liamstask/goose/ - Change database configuration on dbconf.yml like
dialect
anddsn
for each environtment - Do the following command
$ cd $GOPATH/src/github.com/moemoe89/go-grpc-server-tisa
$ goose -env=development up
Make config file for local :
$ cp config-sample.json config-local.json
Build
$ cd $GOPATH/src/github.com/moemoe89/go-grpc-server-tisa
$ make build
Run
$ cd $GOPATH/src/github.com/moemoe89/go-grpc-server-tisa
$ make run
Stop
$ cd $GOPATH/src/github.com/moemoe89/go-grpc-server-tisa
$ make stop
Make config file for docker :
$ cp config-sample.json config-docker.json
Docker Build
$ cd $GOPATH/src/github.com/moemoe89/go-grpc-server-tisa
$ make docker-build
Docker Up
$ cd $GOPATH/src/github.com/moemoe89/go-grpc-server-tisa
$ make docker-up
Docker Down
$ cd $GOPATH/src/github.com/moemoe89/go-grpc-server-tisa
$ make docker-down
Make config file for docker :
$ cp config-sample.json config.json
Build
$ docker-compose build
Run
$ docker-compose up
Stop
$ docker-compose down
- Open BloomRPC
- Import proto file
- Fill server address & port
- Do testing
Run
$ go test ./...
Run with cover
$ go test ./... -cover
Run with HTML output
$ go test ./... -coverprofile=c.out && go tool cover -html=c.out
Thanks to this medium link for sharing the great article
MIT