I am trying to make json-rpc
server in my application using gorilla/rpc
package.
Here is my code
func (server *Server) ListenRPC(port string) {
fmt.Println(fmt.Sprintf(MessageListeningRPCServer, port))
s := rpc.NewServer()
s.RegisterCodec(json.NewCodec(), "application/json")
s.RegisterCodec(json.NewCodec(), "application/json;charset=UTF-8")
s.RegisterService(new(RPCServer), "")
r := mux.NewRouter()
r.Handle("/", s)
http.ListenAndServe(fmt.Sprintf(portFormatter, port), r)
}
type RPCServer struct {
}
type Response string
type Args struct {
A, B int
}
func (server *RPCServer) Abc(r *http.Request, args *Args, response *Response) error {
*response = "asdasdasd"
return nil
}
So in cmd I run curl
command look like this
curl -H 'Content-Type: application/json' -X POST -d '{"method":"RPCServer.Abc","params":[{"a":3}],"id":1}' http://localhost:8090
and get error look like this
rpc: can't find service "RPCServer.Abc"