2020-08-23 20:37:22 +03:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
|
2020-09-20 17:07:36 +03:00
|
|
|
"github.com/unistack-org/micro/v3/network/transport"
|
2020-08-23 20:37:22 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Handle registers the handler for the given pattern.
|
|
|
|
func Handle(pattern string, handler http.Handler) transport.Option {
|
|
|
|
return func(o *transport.Options) {
|
|
|
|
if o.Context == nil {
|
|
|
|
o.Context = context.Background()
|
|
|
|
}
|
|
|
|
handlers, ok := o.Context.Value("http_handlers").(map[string]http.Handler)
|
|
|
|
if !ok {
|
|
|
|
handlers = make(map[string]http.Handler)
|
|
|
|
}
|
|
|
|
handlers[pattern] = handler
|
|
|
|
o.Context = context.WithValue(o.Context, "http_handlers", handlers)
|
|
|
|
}
|
|
|
|
}
|