package rpc import ( "fmt" "net/http" "github.com/gorilla/rpc" "github.com/gorilla/rpc/json" ) // OrionService is the JSON-RPC API type OrionService struct{} // HelloArgs is the arguments expected by the Hello method type HelloArgs struct { Who string } // HelloResponse is the response returned from the Hello method type HelloResponse struct { Message string } // Hello is a demo RPC method fro the OrionService func (o *OrionService) Hello(r *http.Request, args *HelloArgs, reply *HelloResponse) error { reply.Message = fmt.Sprintf("hello %s", args.Who) return nil } // NewServer returns a new configured JSON-RPC server func NewServer() *rpc.Server { server := rpc.NewServer() server.RegisterCodec(json.NewCodec(), "application/json") if err := server.RegisterService(new(OrionService), "Orion"); err != nil { panic(err) } return server }