grpc-gateway Demo項目

倉庫地址

定義一個rcp服務 && grpc-gateway

grpc-gateway

gvm use go1.18.1

安裝插件

go install \
    github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
    github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger \
    github.com/golang/protobuf/protoc-gen-go

wget https://github.com/protocolbuffers/protobuf/releases/download/v21.8/protoc-21.8-osx-aarch_64.zip
unzip protoc-3.2.0-linux-x86_64.zip -d protoc3
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest

編譯文件

單純rpc調用

./bin/protoc --go_out=./service user.proto
./bin/protoc --go_out=./service hello_world.proto
./bin/protoc --go_out ./service_rpc --go-grpc_out ./service_rpc hello_world_rpc.proto
go run rpc_demo/server.go
go run rpc_demo/client.go

rpc轉化爲http

./bin/protoc -I. -I=./third_party  -I=./include \
  --go_out=./service_rcp_http --go_opt=paths=source_relative \
  --go-grpc_out=./service_rcp_http --go-grpc_opt=paths=source_relative \
  --grpc-gateway_out=./service_rcp_http --grpc-gateway_opt=paths=source_relative \
  ./hello_world.proto
go run rpc_http_demo/server.go

最終請求

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章