You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Ethan Buchman 7ea86f6506 fix test race and update readme 9 years ago
client add blank client interface 9 years ago
server Remove go-alert dependency 9 years ago
types support unix domain websockets 9 years ago
LICENSE Initial commit 9 years ago
README.md fix test race and update readme 9 years ago
rpc_test.go fix test race and update readme 9 years ago
version.go version bump 9 years ago

README.md

go-rpc

CircleCI

HTTP RPC server supporting calls via uri params, jsonrpc, and jsonrpc over websockets

How To

Define some types and routes:

// Define a type for results and register concrete versions with go-wire
type Result interface{}

type ResultStatus struct {
	Value string
}

var _ = wire.RegisterInterface(
	struct{ Result }{},
	wire.ConcreteType{&ResultStatus{}, 0x1},
)

// Define some routes
var Routes = map[string]*rpcserver.RPCFunc{
	"status": rpcserver.NewRPCFunc(StatusResult, "arg"),
}

// an rpc function
func StatusResult(v string) (Result, error) {
	return &ResultStatus{v}, nil
}

Now start the server:

mux := http.NewServeMux()
rpcserver.RegisterRPCFuncs(mux, Routes)
wm := rpcserver.NewWebsocketManager(Routes, nil)
mux.HandleFunc("/websocket", wm.WebsocketHandler)
go func() {
	_, err := rpcserver.StartHTTPServer("0.0.0.0:46657", mux)
	if err != nil {
		panic(err)
	}
}()

Note that unix sockets are supported as well (eg. /path/to/socket instead of 0.0.0.0:46657)

Now see all available endpoints by sending a GET request to 0.0.0.0:46657. Each route is available as a GET request, as a JSONRPCv2 POST request, and via JSONRPCv2 over websockets

Examples