Tiny RPC experiment in Go.
After reading the rpc portion of OSTEP and the protobufs section of DDIA, I wanted to implement my own little rpc that includes a decent developer experience. Would not say that it is all that great, but it was mostly for learning purposes, haha.
- parses a small schema language
- checks the schema for basic errors
- generates Go message/client/server code
- serializes requests and responses over HTTP
See schema.md for the current schema format.
Example:
message MessageRequest {
int32 field1 = 1;
float field2 = 2;
}
message MessageResponse {
int32 field1 = 1;
float field2 = 2;
}
service Messenger {
rpc SendMessage(MessageRequest) returns (MessageResponse) {}
}go run . generate path/to/schema-fileThis writes:
path/to/schema-file.go
Start the demo server:
go run . serverIn another terminal, call the demo client:
go run . clientlexer/: tokenizes schema filesparser/: builds the ASTchecker/: validates messages and servicesgenerator/: generates Go codeserializer/: binary encode/decode for tagged structsclient/: HTTP RPC clientserver/: HTTP RPC servercmd/: CLI commands and demo wiring
- supported field types:
int32,int64,bool,string,double,float - RPC definitions currently require an empty body:
{} - generated structs use
myrpctags like`myrpc:"1"`