2015-06-03 03:25:37 +03:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
|
2015-11-20 19:17:33 +03:00
|
|
|
"github.com/micro/go-micro/registry"
|
2015-06-03 03:25:37 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type rpcHandler struct {
|
|
|
|
name string
|
|
|
|
handler interface{}
|
|
|
|
endpoints []*registry.Endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
func newRpcHandler(handler interface{}) Handler {
|
|
|
|
typ := reflect.TypeOf(handler)
|
|
|
|
hdlr := reflect.ValueOf(handler)
|
|
|
|
name := reflect.Indirect(hdlr).Type().Name()
|
|
|
|
|
|
|
|
var endpoints []*registry.Endpoint
|
|
|
|
|
|
|
|
for m := 0; m < typ.NumMethod(); m++ {
|
|
|
|
if e := extractEndpoint(typ.Method(m)); e != nil {
|
2015-10-11 14:05:20 +03:00
|
|
|
e.Name = name + "." + e.Name
|
2015-06-03 03:25:37 +03:00
|
|
|
endpoints = append(endpoints, e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &rpcHandler{
|
|
|
|
name: name,
|
|
|
|
handler: handler,
|
|
|
|
endpoints: endpoints,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcHandler) Name() string {
|
|
|
|
return r.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcHandler) Handler() interface{} {
|
|
|
|
return r.handler
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcHandler) Endpoints() []*registry.Endpoint {
|
|
|
|
return r.endpoints
|
|
|
|
}
|