mirror of
				https://github.com/go-kratos/kratos.git
				synced 2025-10-30 23:47:59 +02:00 
			
		
		
		
	feat(consul): support custom tags for service registration (#3707)
This commit is contained in:
		| @@ -40,6 +40,8 @@ type Client struct { | ||||
| 	deregisterCriticalServiceAfter int | ||||
| 	// serviceChecks  user custom checks | ||||
| 	serviceChecks api.AgentServiceChecks | ||||
| 	// tags is service tags | ||||
| 	tags []string | ||||
|  | ||||
| 	// used to control heartbeat | ||||
| 	lock      sync.RWMutex | ||||
| @@ -166,11 +168,15 @@ func (c *Client) Register(ctx context.Context, svc *registry.ServiceInstance, en | ||||
| 		checkAddresses = append(checkAddresses, net.JoinHostPort(addr, strconv.FormatUint(port, 10))) | ||||
| 		addresses[raw.Scheme] = api.ServiceAddress{Address: endpoint, Port: int(port)} | ||||
| 	} | ||||
| 	tags := []string{fmt.Sprintf("version=%s", svc.Version)} | ||||
| 	if len(c.tags) > 0 { | ||||
| 		tags = append(tags, c.tags...) | ||||
| 	} | ||||
| 	asr := &api.AgentServiceRegistration{ | ||||
| 		ID:              svc.ID, | ||||
| 		Name:            svc.Name, | ||||
| 		Meta:            svc.Metadata, | ||||
| 		Tags:            []string{fmt.Sprintf("version=%s", svc.Version)}, | ||||
| 		Tags:            tags, | ||||
| 		TaggedAddresses: addresses, | ||||
| 	} | ||||
| 	if len(checkAddresses) > 0 { | ||||
|   | ||||
| @@ -86,6 +86,15 @@ func WithServiceCheck(checks ...*api.AgentServiceCheck) Option { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // WithTags with service tags. | ||||
| func WithTags(tags []string) Option { | ||||
| 	return func(o *Registry) { | ||||
| 		if o.cli != nil { | ||||
| 			o.cli.tags = tags | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // Config is consul registry config | ||||
| type Config struct { | ||||
| 	*api.Config | ||||
|   | ||||
		Reference in New Issue
	
	Block a user