micro v4 fix

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2023-08-16 15:27:07 +03:00
parent 259e1d275e
commit 966bc31eb2

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
}