Sample HWSC service using gRPC in GoLang
-
Install go version go 1.11.1
-
Configure terminal $GOPATH, $GOROOT, and add your go workspace bin in $PATH in your ~/.bash_profile (your paths may vary)
# this is my sample ~/.bash_profile PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}" export PATH export GOROOT="/usr/local/go" export GOPATH="$HOME/go_workspace" export PATH="$HOME/protobuf-3.6.1/src:$HOME/go_workspace/bin:$PATH" parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } export PS1="\[\033[36m\]\u\[\033[32m\]:\[\033[33;1m\]\w\[\033[32m\]\$(parse_git_branch)\[\033[m\]\$ " export CLICOLOR=1 export LSCOLORS=ExFxBxDxCxegedabagacad alias ls='ls -GFh'
-
Run
$ go get -u github.com/golang/dep/cmd/dep
(GoLang Dependency Management) -
Run
$ bash $GOPATH/src/github.com/golang/dep/install.sh
-
Verify dep installation
$ dep version
-
Make a new GitHub repository (Assuming we are creating a new service repo https://github.com/hwsc-org/empty-sample)
-
Run
$ go get -u github.com/hwsc-org/empty-sample
-
Change Directory
$ cd $GOPATH/src/github.com/hwsc-org/empty-sample
-
Run the following commands
$ dep init $ ls Gopkg.toml Gopkg.lock vendor/
-
Make main.go file
package main import ( "fmt" ) func main() { fmt.Println("Hello, playground") }
-
Add constraint "google.golang.org/grpc" Gopkg.toml to point to a gRPC specific commit revision
[[constraint]] name = "google.golang.org/grpc" version = "1.16.0"
-
Download, extract protocol buffers 3.6.1, and install (takes a while) guide
-
Add the protoc binary to your $PATH (refer to step 2)
-
Run
$ go get -u github.com/golang/protobuf/protoc-gen-go
-
Define your proto in hwsc-api-blocks under folder "proto"; basic guide, with REST guide, example
-
[OPTIONAL] To inject an additional tag like
bson
, install and include protoc-go-inject-tag -
Modify generate {int,ext} protoc script in hwsc-api-blocks , example
-
[OPTIONAL] Run
$ dep ensure -v
or$ dep ensure -update
from the root folder of the project to populate dependencies in the vendor folder (run as you add external dependencies) -
[OPTIONAL] Run your generate protoc script or as needed, example result
-
Implement server's entry point
-
Implement service