From 2327e1d4e8d3564c3ade0bc6f00f4196ccabe673 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 3 Apr 2017 15:03:46 +0100 Subject: [PATCH] Set endpoint metadata in the http server --- handler.go | 3 ++- http.go | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/handler.go b/handler.go index 4d971af..0763ffd 100644 --- a/handler.go +++ b/handler.go @@ -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 { diff --git a/http.go b/http.go index 02fa234..60a92c7 100644 --- a/http.go +++ b/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),