Merge pull request 'micro v4 fix' (#175) from micro4 into master

Reviewed-on: #175
This commit is contained in:
Василий Толстов 2023-08-16 15:27:32 +03:00
commit 5c2cba3ecc

22
http.go
View File

@ -122,12 +122,22 @@ func (h *Server) Init(opts ...options.Option) error {
func (h *Server) Handle(handler interface{}, opts ...options.Option) error {
options := server.NewHandleOptions(opts...)
var endpointMetadata []EndpointMetadata
if v, ok := options.Context.Value(handlerEndpointsKey{}).([]EndpointMetadata); ok {
endpointMetadata = v
}
// passed unknown handler
hdlr, ok := handler.(*httpHandler)
if !ok {
h.Lock()
h.hd = handler
if h.handlers == nil {
h.handlers = make(map[string]interface{})
}
for _, v := range endpointMetadata {
h.handlers[v.Name] = h.newHTTPHandler(handler, opts...)
}
h.Unlock()
return nil
}
@ -140,16 +150,6 @@ func (h *Server) Handle(handler interface{}, opts ...options.Option) error {
return nil
}
// passed micro compat handler
h.Lock()
if h.handlers == nil {
h.handlers = make(map[string]interface{})
}
for k := range options.Metadata {
h.handlers[k] = handler
}
h.Unlock()
return nil
}