Set consul token via registry options.

Optionally configure a token to use with the consul client.
This commit is contained in:
chriss 2016-11-18 00:07:12 +00:00
parent 3d7187f405
commit 8a25723fe0
2 changed files with 13 additions and 0 deletions

View File

@ -14,3 +14,12 @@ func Config(c *consul.Config) registry.Option {
o.Context = context.WithValue(o.Context, "consul_config", c) 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)
}
}

View File

@ -59,6 +59,10 @@ func newConsulRegistry(opts ...Option) Registry {
if c != nil { if c != nil {
config = c.(*consul.Config) config = c.(*consul.Config)
} }
t := options.Context.Value("consul_token")
if t != nil {
config.Token = t.(string)
}
} }
// set timeout // set timeout