Skip to content

Jcho114/myrpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

myrpc

Tiny RPC experiment in Go.

Motivation

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.

What It Does

  • parses a small schema language
  • checks the schema for basic errors
  • generates Go message/client/server code
  • serializes requests and responses over HTTP

Schema

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) {}
}

Generate Code

go run . generate path/to/schema-file

This writes:

path/to/schema-file.go

Demo Commands

Start the demo server:

go run . server

In another terminal, call the demo client:

go run . client

Project Layout

  • lexer/: tokenizes schema files
  • parser/: builds the AST
  • checker/: validates messages and services
  • generator/: generates Go code
  • serializer/: binary encode/decode for tagged structs
  • client/: HTTP RPC client
  • server/: HTTP RPC server
  • cmd/: CLI commands and demo wiring

Notes

  • supported field types: int32, int64, bool, string, double, float
  • RPC definitions currently require an empty body: {}
  • generated structs use myrpc tags like `myrpc:"1"`

About

Toy implementation of a custom rpc library for learning purposes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages