Skip to content

Commit

Permalink
Server and router now accept service name
Browse files Browse the repository at this point in the history
  • Loading branch information
pipe01 committed Jan 28, 2021
1 parent 5a60bd7 commit fa5b765
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions router/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit fa5b765

Please sign in to comment.