feat: registry.
This commit is contained in:
75
registry/consul/options.go
Normal file
75
registry/consul/options.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package consul
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/consul/api"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Option is consul registry option.
|
||||
type Option func(*Registry)
|
||||
|
||||
// WithHealthCheck with registry health check option.
|
||||
func WithHealthCheck(enable bool) Option {
|
||||
return func(o *Registry) {
|
||||
o.enableHealthCheck = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithTimeout with get services timeout option.
|
||||
func WithTimeout(timeout time.Duration) Option {
|
||||
return func(o *Registry) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
}
|
||||
|
||||
// WithDatacenter with registry datacenter option
|
||||
func WithDatacenter(dc Datacenter) Option {
|
||||
return func(o *Registry) {
|
||||
o.cli.dc = dc
|
||||
}
|
||||
}
|
||||
|
||||
// WithHeartbeat enable or disable heartbeat
|
||||
func WithHeartbeat(enable bool) Option {
|
||||
return func(o *Registry) {
|
||||
if o.cli != nil {
|
||||
o.cli.heartbeat = enable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithServiceResolver with endpoint function option.
|
||||
func WithServiceResolver(fn ServiceResolver) Option {
|
||||
return func(o *Registry) {
|
||||
if o.cli != nil {
|
||||
o.cli.resolver = fn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithHealthCheckInterval with healthcheck interval in seconds.
|
||||
func WithHealthCheckInterval(interval int) Option {
|
||||
return func(o *Registry) {
|
||||
if o.cli != nil {
|
||||
o.cli.healthcheckInterval = interval
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithDeregisterCriticalServiceAfter with deregister-critical-service-after in seconds.
|
||||
func WithDeregisterCriticalServiceAfter(interval int) Option {
|
||||
return func(o *Registry) {
|
||||
if o.cli != nil {
|
||||
o.cli.deregisterCriticalServiceAfter = interval
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithServiceCheck with service checks
|
||||
func WithServiceCheck(checks ...*api.AgentServiceCheck) Option {
|
||||
return func(o *Registry) {
|
||||
if o.cli != nil {
|
||||
o.cli.serviceChecks = checks
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user