Set endpoint metadata in the http server
This commit is contained in:
parent
31f1702ab2
commit
2327e1d4e8
@ -7,6 +7,7 @@ import (
|
||||
|
||||
type httpHandler struct {
|
||||
opts server.HandlerOptions
|
||||
eps []*registry.Endpoint
|
||||
hd interface{}
|
||||
}
|
||||
|
||||
@ -19,7 +20,7 @@ func (h *httpHandler) Handler() interface{} {
|
||||
}
|
||||
|
||||
func (h *httpHandler) Endpoints() []*registry.Endpoint {
|
||||
return []*registry.Endpoint{}
|
||||
return h.eps
|
||||
}
|
||||
|
||||
func (h *httpHandler) Options() server.HandlerOptions {
|
||||
|
21
http.go
21
http.go
@ -50,14 +50,29 @@ func (h *httpServer) Handle(handler server.Handler) error {
|
||||
}
|
||||
|
||||
func (h *httpServer) NewHandler(handler interface{}, opts ...server.HandlerOption) server.Handler {
|
||||
var options server.HandlerOptions
|
||||
options := server.HandlerOptions{
|
||||
Metadata: make(map[string]map[string]string),
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
var eps []*registry.Endpoint
|
||||
|
||||
if !options.Internal {
|
||||
for name, metadata := range options.Metadata {
|
||||
eps = append(eps, ®istry.Endpoint{
|
||||
Name: name,
|
||||
Metadata: metadata,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return &httpHandler{
|
||||
opts: options,
|
||||
eps: eps,
|
||||
hd: handler,
|
||||
opts: options,
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,9 +96,11 @@ func (h *httpServer) Subscribe(s server.Subscriber) error {
|
||||
func (h *httpServer) Register() error {
|
||||
h.Lock()
|
||||
opts := h.opts
|
||||
eps := h.hd.Endpoints()
|
||||
h.Unlock()
|
||||
|
||||
service := serviceDef(opts)
|
||||
service.Endpoints = eps
|
||||
|
||||
rOpts := []registry.RegisterOption{
|
||||
registry.RegisterTTL(opts.RegisterTTL),
|
||||
|
Loading…
Reference in New Issue
Block a user