$ node -v
v10.17.0
$ yarn -v
1.21.1
Probably the latest version of node.js will cause build errors on node-gyp
and grpc
.
$ yarn install
$ yarn start
Using gRPCurl
$ go get github.com/fullstorydev/grpcurl
$ go install github.com/fullstorydev/grpcurl/cmd/grpcurl
$ grpcurl -d '{"champion_id": 1}' -plaintext -proto rpc/rpc.proto -import-path protos 127.0.0.1:5000 rpc.Rpc/GetChampion
{
"champion": {
"championId": 1,
"type": "ASSASSIN",
"name": "Akali",
"message": "If you look dangerous, you better be dangerous."
}
}
$ grpcurl -plaintext -proto rpc/rpc.proto -import-path protos 127.0.0.1:5000 rpc.Rpc/ListChampions
{
"champions": [
{
"championId": 1,
"type": "ASSASSIN",
"name": "Akali",
"message": "If you look dangerous, you better be dangerous."
},
{
"championId": 2,
"type": "MAGE",
"name": "Kennen",
"message": "The Heart of the Tempest beats eternal...and those beaten remember eternally."
},
{
"championId": 3,
"type": "FIGHTER",
"name": "Tryndamere",
"message": "Rage is my weapon."
}
]
}
$ grpcurl -plaintext -proto rpc/rpc.proto -import-path protos 127.0.0.1:5000 rpc.Rpc/GetBattleField
{
"battleField": {
"battleFieldId": 2,
"name": "The Twisted Treeline"
}
}
This is a bash script that generates code to under codegen
dir using proto files under the protos
dir.
$ yarn gen
There are two ways to generate code: using grpc-tools
and using protbuf.js
. The code generated by protobuf.js is kinder and easier to use.