1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-10-06 21:46:55 +02:00

fix consul context key mismatch (#2801)

This commit is contained in:
Tsln
2025-08-29 14:39:20 +08:00
committed by GitHub
parent 95540b7859
commit 479bd58c3f

View File

@@ -82,18 +82,18 @@ func configure(c *consulRegistry, opts ...registry.Option) {
if c.opts.Context != nil {
// Use the consul config passed in the options, if available
if co, ok := c.opts.Context.Value("consul_config").(*consul.Config); ok {
if co, ok := c.opts.Context.Value(consulConfigKey).(*consul.Config); ok {
config = co
}
if cn, ok := c.opts.Context.Value("consul_connect").(bool); ok {
if cn, ok := c.opts.Context.Value(consulConnectKey).(bool); ok {
c.connect = cn
}
// Use the consul query options passed in the options, if available
if qo, ok := c.opts.Context.Value("consul_query_options").(*consul.QueryOptions); ok && qo != nil {
if qo, ok := c.opts.Context.Value(consulQueryOptionsKey).(*consul.QueryOptions); ok && qo != nil {
c.queryOptions = qo
}
if as, ok := c.opts.Context.Value("consul_allow_stale").(bool); ok {
if as, ok := c.opts.Context.Value(consulAllowStaleKey).(bool); ok {
c.queryOptions.AllowStale = as
}
}
@@ -182,12 +182,12 @@ func (c *consulRegistry) Register(s *registry.Service, opts ...registry.Register
}
if c.opts.Context != nil {
if tcpCheckInterval, ok := c.opts.Context.Value("consul_tcp_check").(time.Duration); ok {
if tcpCheckInterval, ok := c.opts.Context.Value(consulTCPCheckKey).(time.Duration); ok {
regTCPCheck = true
regInterval = tcpCheckInterval
}
var ok bool
if httpCheckConfig, ok = c.opts.Context.Value("consul_http_check_config").(consul.AgentServiceCheck); ok {
if httpCheckConfig, ok = c.opts.Context.Value(consulHTTPCheckConfigKey).(consul.AgentServiceCheck); ok {
regHTTPCheck = true
}
}