bidirpc is a simple bi-direction RPC library.
import (
"io"
"log"
"github.com/zhuyie/bidirpc"
)
type YourService struct{}
var conn io.ReadWriteCloser
// Create a registry, and register your available services, YourService follows
// net/rpc semantics
registry := bidirpc.NewRegistry()
registry.Register(&YourService{})
// TODO: Establish your connection before passing it to the session
// Create a new session
session, err := bidirpc.NewSession(conn, bidirpc.Yin, registry, 0)
if err != nil {
log.Fatal(err)
}
// Clean up session resources
defer func() {
if err := session.Close(); err != nil {
log.Fatal(err)
}
}()
// Start the event loop, this is a blocking call, so place it in a goroutine
// if you need to move on. The call will return when the connection is
// terminated.
if err = session.Serve(); err != nil {
log.Fatal(err)
}