feat(registry): consul support user custom checks (#2317)

pull/2321/head
包子 2 years ago committed by GitHub
parent 73a8323ee7
commit b354f185c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      contrib/registry/consul/client.go
  2. 9
      contrib/registry/consul/registry.go

@ -29,6 +29,8 @@ type Client struct {
heartbeat bool
// deregisterCriticalServiceAfter time interval in seconds
deregisterCriticalServiceAfter int
// serviceChecks user custom checks
serviceChecks api.AgentServiceChecks
}
// NewClient creates consul client
@ -139,6 +141,9 @@ func (c *Client) Register(_ context.Context, svc *registry.ServiceInstance, enab
})
}
// custom checks
asr.Checks = append(asr.Checks, c.serviceChecks...)
err := c.cli.Agent().ServiceRegister(asr)
if err != nil {
return err

@ -63,6 +63,15 @@ func WithDeregisterCriticalServiceAfter(interval int) Option {
}
}
// WithServiceCheck with service checks
func WithServiceCheck(checks ...*api.AgentServiceCheck) Option {
return func(o *Registry) {
if o.cli != nil {
o.cli.serviceChecks = checks
}
}
}
// Config is consul registry config
type Config struct {
*api.Config

Loading…
Cancel
Save