From 8a25723fe07c02d47308a32e629b2fe11184c91a Mon Sep 17 00:00:00 2001 From: chriss Date: Fri, 18 Nov 2016 00:07:12 +0000 Subject: [PATCH] Set consul token via registry options. Optionally configure a token to use with the consul client. --- registry/consul/options.go | 9 +++++++++ registry/consul_registry.go | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/registry/consul/options.go b/registry/consul/options.go index 3c28d45d..f85bbf79 100644 --- a/registry/consul/options.go +++ b/registry/consul/options.go @@ -14,3 +14,12 @@ func Config(c *consul.Config) registry.Option { o.Context = context.WithValue(o.Context, "consul_config", c) } } + +func Token(t string) registry.Option { + return func(o *registry.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, "consul_token", t) + } +} diff --git a/registry/consul_registry.go b/registry/consul_registry.go index 3d34c09d..32a12490 100644 --- a/registry/consul_registry.go +++ b/registry/consul_registry.go @@ -59,6 +59,10 @@ func newConsulRegistry(opts ...Option) Registry { if c != nil { config = c.(*consul.Config) } + t := options.Context.Value("consul_token") + if t != nil { + config.Token = t.(string) + } } // set timeout