github.com/annwntech/go-micro/v2@v2.9.5/broker/http/options.go (about) 1 package http 2 3 import ( 4 "context" 5 "net/http" 6 7 "github.com/annwntech/go-micro/v2/broker" 8 ) 9 10 // Handle registers the handler for the given pattern. 11 func Handle(pattern string, handler http.Handler) broker.Option { 12 return func(o *broker.Options) { 13 if o.Context == nil { 14 o.Context = context.Background() 15 } 16 handlers, ok := o.Context.Value("http_handlers").(map[string]http.Handler) 17 if !ok { 18 handlers = make(map[string]http.Handler) 19 } 20 handlers[pattern] = handler 21 o.Context = context.WithValue(o.Context, "http_handlers", handlers) 22 } 23 }