mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-30 08:06:40 +02:00
bc71640fd9
* broker: swap default broker from eats to http Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
24 lines
549 B
Go
24 lines
549 B
Go
package http
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/micro/go-micro/v2/broker"
|
|
)
|
|
|
|
// Handle registers the handler for the given pattern.
|
|
func Handle(pattern string, handler http.Handler) broker.Option {
|
|
return func(o *broker.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)
|
|
}
|
|
}
|