From 8245390b5a4872330a98d1ce5e3681dfb8dd9a18 Mon Sep 17 00:00:00 2001 From: Asim Date: Thu, 26 May 2016 18:01:02 +0100 Subject: [PATCH 1/3] Support endpoint metadata --- server/handler.go | 9 +++++++++ server/rpc_handler.go | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/server/handler.go b/server/handler.go index b944efeb..d3a25d86 100644 --- a/server/handler.go +++ b/server/handler.go @@ -34,6 +34,7 @@ type Subscriber interface { type HandlerOptions struct { Internal bool + Metadata map[string]map[string]string } type SubscriberOptions struct { @@ -50,6 +51,14 @@ func InternalHandler(b bool) HandlerOption { } } +// EndpointMetadata is a Handler option that allows metadata to be added to +// individual endpoints. +func EndpointMetadata(endpoint string, metadata map[string]string) HandlerOption { + return func(o *HandlerOptions) { + o.Metadata[endpoint] = metadata + } +} + // Internal Subscriber options specifies that a subscriber is not advertised // to the discovery system. func InternalSubscriber(b bool) SubscriberOption { diff --git a/server/rpc_handler.go b/server/rpc_handler.go index e01b4b25..42ec7f0f 100644 --- a/server/rpc_handler.go +++ b/server/rpc_handler.go @@ -14,7 +14,10 @@ type rpcHandler struct { } func newRpcHandler(handler interface{}, opts ...HandlerOption) Handler { - var options HandlerOptions + options := HandlerOptions{ + Metadata: make(map[string]map[string]string), + } + for _, o := range opts { o(&options) } @@ -28,6 +31,11 @@ func newRpcHandler(handler interface{}, opts ...HandlerOption) Handler { for m := 0; m < typ.NumMethod(); m++ { if e := extractEndpoint(typ.Method(m)); e != nil { e.Name = name + "." + e.Name + + for k, v := range options.Metadata[e.Name] { + e.Metadata[k] = v + } + endpoints = append(endpoints, e) } } From ee3ae89ca805e1a33c39eaaf60623710b577fa2d Mon Sep 17 00:00:00 2001 From: Asim Date: Thu, 26 May 2016 20:25:00 +0100 Subject: [PATCH 2/3] naming nitpick --- server/handler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/handler.go b/server/handler.go index d3a25d86..79543b8b 100644 --- a/server/handler.go +++ b/server/handler.go @@ -53,9 +53,9 @@ func InternalHandler(b bool) HandlerOption { // EndpointMetadata is a Handler option that allows metadata to be added to // individual endpoints. -func EndpointMetadata(endpoint string, metadata map[string]string) HandlerOption { +func EndpointMetadata(name string, md map[string]string) HandlerOption { return func(o *HandlerOptions) { - o.Metadata[endpoint] = metadata + o.Metadata[name] = md } } From 7a5a9013ef4a34135603c56e0a53f30dc35afe03 Mon Sep 17 00:00:00 2001 From: Asim Date: Thu, 26 May 2016 20:43:05 +0100 Subject: [PATCH 3/3] move the option --- server/handler.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server/handler.go b/server/handler.go index 79543b8b..5e81e5c3 100644 --- a/server/handler.go +++ b/server/handler.go @@ -42,6 +42,14 @@ type SubscriberOptions struct { Internal bool } +// EndpointMetadata is a Handler option that allows metadata to be added to +// individual endpoints. +func EndpointMetadata(name string, md map[string]string) HandlerOption { + return func(o *HandlerOptions) { + o.Metadata[name] = md + } +} + // Internal Handler options specifies that a handler is not advertised // to the discovery system. In the future this may also limit request // to the internal network or authorised user. @@ -51,14 +59,6 @@ func InternalHandler(b bool) HandlerOption { } } -// EndpointMetadata is a Handler option that allows metadata to be added to -// individual endpoints. -func EndpointMetadata(name string, md map[string]string) HandlerOption { - return func(o *HandlerOptions) { - o.Metadata[name] = md - } -} - // Internal Subscriber options specifies that a subscriber is not advertised // to the discovery system. func InternalSubscriber(b bool) SubscriberOption {