Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Latest commit

 

History

History
69 lines (58 loc) · 3.34 KB

README.md

File metadata and controls

69 lines (58 loc) · 3.34 KB

hwsc-grpc-sample-svc

Sample HWSC service using gRPC in GoLang

Creating HWSC GoLang Service

  1. Install go version go 1.11.1

  2. 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'
  3. Run $ go get -u github.com/golang/dep/cmd/dep (GoLang Dependency Management)

  4. Run $ bash $GOPATH/src/github.com/golang/dep/install.sh

  5. Verify dep installation $ dep version

  6. Make a new GitHub repository (Assuming we are creating a new service repo https://github.com/hwsc-org/empty-sample)

  7. Run $ go get -u github.com/hwsc-org/empty-sample

  8. Change Directory $ cd $GOPATH/src/github.com/hwsc-org/empty-sample

  9. Run the following commands

    $ dep init
    $ ls
      Gopkg.toml Gopkg.lock vendor/
  10. Make main.go file

     package main
    
     import (
     	"fmt"
     )
     
     func main() {
     	fmt.Println("Hello, playground")
     }
  11. 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"
  12. Download, extract protocol buffers 3.6.1, and install (takes a while) guide

  13. Add the protoc binary to your $PATH (refer to step 2)

  14. Run $ go get -u github.com/golang/protobuf/protoc-gen-go

  15. Define your proto in hwsc-api-blocks under folder "proto"; basic guide, with REST guide, example

  16. [OPTIONAL] To inject an additional tag like bson, install and include protoc-go-inject-tag

  17. Modify generate {int,ext} protoc script in hwsc-api-blocks , example

  18. [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)

  19. [OPTIONAL] Run your generate protoc script or as needed, example result

  20. Implement server's entry point

  21. Implement service