前提 go 、grcp 、protobuf 已经安装
1 设置go代理
#Go 版本是 1.13 及以上 (推荐)
$ go env -w GOPROXY=https://goproxy.io,direct
#Go 版本是 1.12 及以下
$ export GOPROXY=https://goproxy.io
2 设置go环境变量
export GO111MODULE=on
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export GOPATH=/home/user/code/golang/goPath
export PATH=$PATH:${GOROOT}/bin:$GOPATH/bin
#如需永久生效 把以上内容配置到 /etc/profile 最后一行
$ source /etc/profile
3 下载 安装插件
$ go get github.com/golang/protobuf/protoc-gen-go
4 测试
#下载 example
$ git clone -b v1.30.0 https://github.com/grpc/grpc-go
#启动server
$ cd grpc-go/examples/helloworld/greeter_server
$ go run main.go
#注意!!! 光标闪烁即启动完成 没有任何提示,别入坑
#启动client
$cd grpc-go/examples/helloworld/greeter_client
$ go run main.go
#输出
Greeting: Hello world