Skip to content

zhuyie/bidirpc

Repository files navigation

bidirpc

GoDoc MIT licensed Build Status Coverage Statusd

bidirpc is a simple bi-direction RPC library.

Usage

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

About

bidirpc is a simple bi-direction RPC library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages