From 966bc31eb268b96438e6416c2f31be19495034b9 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 16 Aug 2023 15:27:07 +0300 Subject: [PATCH] micro v4 fix Signed-off-by: Vasiliy Tolstov --- http.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/http.go b/http.go index 75d2486..97da7b2 100644 --- a/http.go +++ b/http.go @@ -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 } -- 2.45.2