gorilla / rpc

Package gorilla/rpc is a golang foundation for RPC over HTTP services.
https://gorilla.github.io
BSD 3-Clause "New" or "Revised" License
595 stars 179 forks source link

registering function as a service #68

Open krisiasty opened 5 years ago

krisiasty commented 5 years ago

I would like to handle method names which are not in a form "Service.Method", whch seems currently imposible.

One way to handle this would be to have *(Server) RegisterFunc** method accepting function and string with a method name as parameters.

Example usage:

func HeartBeat(r *http.Request, args *HeartBeatArgs, reply *HeartBeatReply) error {
    reply.TimeStamp = time.Now().UnixNano()
}

s := rpc.NewServer()
s.RegisterService(heartBeat, "heartBeat")

That way any call with method "heartBeat" should be directed to function HeartBeat.

ansermino commented 5 years ago

I would also like to know if this is possible. I suspect either using a custom codec or intercepting the http request would make this possible. Any thoughts?

ansermino commented 5 years ago

Looking at https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/v2/server.go#L176 it seems that Intercept nor Before functions would get the chance to modify the method/service name before an error is thrown.

painhardcore commented 4 years ago

Hit the same issue, but found the solution in https://github.com/divan/gorilla-xmlrpc/issues/14