diff --git a/server/handler.go b/server/handler.go index b944efeb..5e81e5c3 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 { @@ -41,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. 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) } }