diff --git a/router/handler.go b/router/handler.go index 67be2d5..aaeed16 100644 --- a/router/handler.go +++ b/router/handler.go @@ -25,10 +25,8 @@ func (e *HandlerError) Unwrap() error { return e.err } -func newHandler(h interface{}, methods map[string]bool) *handler { +func newHandler(h interface{}, name string, methods map[string]bool) *handler { handtype := reflect.TypeOf(h) - handval := reflect.ValueOf(h) - name := reflect.Indirect(handval).Type().Name() endpoints := make(map[string]*endpoint) diff --git a/router/router.go b/router/router.go index c125fbc..674e64a 100644 --- a/router/router.go +++ b/router/router.go @@ -15,7 +15,7 @@ var ErrMalformedPath = errors.New("malformed request path") var ErrEndpointNotFound = errors.New("endpoint not found") type Router interface { - AddHandler(h interface{}, methods []string) + AddHandler(h interface{}, name string, methods []string) Handle(path string, data []byte) ([]byte, error) } @@ -33,13 +33,13 @@ func NewRouter(cod codec.Codec, log logger.Logger) Router { } } -func (s *router) AddHandler(h interface{}, methods []string) { +func (s *router) AddHandler(h interface{}, name string, methods []string) { metmap := make(map[string]bool, len(methods)) for _, m := range methods { metmap[m] = true } - hdl := newHandler(h, metmap) + hdl := newHandler(h, name, metmap) s.handlers[hdl.Name] = hdl for k := range hdl.Endpoints { diff --git a/server/server.go b/server/server.go index d7c4525..fe3fb52 100644 --- a/server/server.go +++ b/server/server.go @@ -14,7 +14,7 @@ import ( type Server interface { Start() error - AddHandler(h interface{}, methods ...string) + AddHandler(h interface{}, name string, methods ...string) Publish(ctx context.Context, topic string, data interface{}) error } @@ -45,8 +45,8 @@ func (s *server) Start() error { return nil } -func (s *server) AddHandler(h interface{}, methods ...string) { - s.opts.Router.AddHandler(h, methods) +func (s *server) AddHandler(h interface{}, name string, methods ...string) { + s.opts.Router.AddHandler(h, name, methods) } func (s *server) handle(soc transport.Socket) {