Set consul token via registry options.
Optionally configure a token to use with the consul client.
This commit is contained in:
parent
3d7187f405
commit
8a25723fe0
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user