This is sample reverse string tutorial to explain grpc between go server and go client/netcore2 client..
It has following source code folders
- go server
- go client
- netcore2 csharp client
Below instructions are only for macOS X. i assume below steps might also works for linux.
- Homebrew command line package manager utility
- Go lang compiler
- Python@2, which comes default with macOS X
- .Net core SDK, this project uses netcoreapp2.1
- protoc compiler
- grpc command line tool
- grpc_csharp_plugin command line plugin tool
goto https://www.microsoft.com/net/download download Build apps SDK x64 installer run installer
gRPC requires Go 1.6 or higher.
$ go version
If go is not installed, you can install via Homebrew package manager and setup path variables. Ref: https://stackoverflow.com/a/40129734
brew install go
export GOPATH=$HOME/.golang
export PATH=$PATH:$GOPATH/bin
Use the following command to install gRPC.
$ go get -u google.golang.org/grpc
Ref: http://google.github.io/proto-lens/installing-protoc.html
brew install protobuf
Next, install the protoc plugin for Go
$ go get -u github.com/golang/protobuf/protoc-gen-go
git clone https://github.com/pastmaster007/samproto
cd samproto
#compile proto file into pb.go file
protoc -I ./sample ./sample/sample.proto --go_out=plugins=grpc:./sample
# run go server
go run ./goserver/main.go
open another tab in terminal
# run go client
go run ./goclient/main.go
open anothet tab in terminal for net core client
cd netcoreclient
dotnet run
# creates new dotnet console app
dotnet new console
# add required packages to compile and run
dotnet add package Google.Protobuf
dotnet add package Grpc
# add required packages to compile, after package download we can remove this package reference from .csproj file.
dotnet add package grpc.tools
# generates grpc files using proto file.
# make sure "protoc-gen-grpc" plugin requires full file path
~/.nuget/packages/grpc.tools/1.15.0/tools/macosx_x64/protoc \
-I../sample --csharp_out . --grpc_out . ../sample/sample.proto \
--plugin=protoc-gen-grpc=/Users/swx/.nuget/packages/grpc.tools/1.15.0/tools/macosx_x64/grpc_csharp_plugin
Refs:
- https://stackoverflow.com/questions/42589461/how-to-install-nuget-package-in-asp-net-core-project-by-the-cli#42595242
- protocolbuffers/protobuf#791 (comment)
- https://www.sanarias.com/blog/1216AsimplegRPCdemoinGoandCSharp
- https://grpc.io/docs/quickstart/go.html
- grpc/grpc-dart#37 (comment)
- http://google.github.io/proto-lens/installing-protoc.html
- https://grpc.io/docs/quickstart/csharp.html
- https://groups.google.com/d/msg/golang-nuts/Qs8d56uavVs/Pe1Jcou5JUEJ