Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Context specifies the execution context for Consul operations.
// If nil, context.Background() will be used.
Context context.Context
// Address is the address of the Consul agent to connect to.
// Default: "127.0.0.1:8500"
Address string
// Datacenter specifies the Consul datacenter to use.
// If empty, the agent's default datacenter is used.
Datacenter string
// Token is the Consul ACL token used for authenticated requests.
Token string
// Timeout specifies the maximum duration for Consul requests.
// Default: 10s
Timeout time.Duration
// ActorSystemName is the name of the actor system.
// It is used as the service identifier when registering with Consul.
ActorSystemName string
// Host is the hostname or IP address of the actor system.
// It is used to register the service in Consul.
Host string
// DiscoveryPort is the TCP port on which the actor system listens
// for service discovery requests.
DiscoveryPort int
// QueryOptions specifies advanced options for Consul queries.
// May be nil for default behavior.
QueryOptions *QueryOptions
// HealthCheck configures the Consul health check for the registered service.
// May be nil to disable health checks.
HealthCheck *HealthCheck
}
Config defines the configuration options for the Consul provider.
It controls how the provider connects to Consul, registers the service, and configures discovery and health-check behavior.
type Discovery ¶
type Discovery struct {
// contains filtered or unexported fields
}
Discovery represents the Consul discovery provider.
func NewDiscovery ¶
NewDiscovery creates a new instance of the Consul discovery provider. It initializes the provider with the given configuration and sets the initial state. It returns a pointer to the Discovery instance.
func (*Discovery) Deregister ¶
Deregister removes this node from the Consul service discovery.
func (*Discovery) DiscoverPeers ¶
DiscoverPeers retrieves the list of peers registered in Consul. It returns a slice of strings containing the addresses of the peers.
func (*Discovery) Initialize ¶
Initialize initializes the consul discovery provider It creates a new consul client and checks if the connection is valid.
type HealthCheck ¶
type HealthCheck struct {
// Interval is the frequency at which Consul performs the health check.
// Default: 10s
Interval time.Duration
// Timeout is the maximum duration Consul waits for a health check response.
// If the timeout is exceeded, the check is considered failed.
// Default: 3s
Timeout time.Duration
}
HealthCheck defines the configuration of a Consul health check associated with a registered service.
Health checks allow Consul to automatically mark services as unhealthy if they fail within the configured thresholds.
type QueryOptions ¶
type QueryOptions struct {
// OnlyPassing specifies whether to return only services with a passing health check.
// If false, all services (healthy or not) may be returned.
OnlyPassing bool
// Near specifies a node name to sort results by network distance to that node.
// If empty, no distance-based sorting is applied.
Near string
// WaitTime is the maximum duration to wait for changes when using Consul blocking queries.
// If zero, the default agent wait time is used.
WaitTime time.Duration
// Datacenter specifies the Consul datacenter to query.
// If empty, the agent's default datacenter is used.
Datacenter string
// AllowStale indicates whether stale results are acceptable.
// When true, results may be served from follower nodes, improving availability
// at the cost of potentially outdated data.
AllowStale bool
}
QueryOptions defines advanced options for Consul service discovery queries.
These options control how results are filtered, sorted, and fetched from Consul's catalog.