Documentation ¶
Index ¶
- Constants
- func CandidateDefaultLeaderKVValueProvider(c *Candidate) ([]byte, error)
- func IsNotFoundError(err error) bool
- func LazyRandomString(n int) string
- func LocalAddress() (string, error)
- func LocalAddressIP() (net.IP, error)
- func RandomLocalPort() int
- func ReplaceSlugs(s string, p SlugParams) string
- func SpecificCatalogService(serviceID string, svcs []*api.CatalogService) (*api.CatalogService, bool)
- func SpecificChecks(serviceID string, checks api.HealthChecks) api.HealthChecks
- func SpecificServiceEntry(serviceID string, svcs []*api.ServiceEntry) (*api.ServiceEntry, bool)
- func WatchAgentService(serviceID string) (*watch.Plan, error)
- func WatchAgentServiceHandler(serviceID string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
- func WatchAgentServiceHybridHandler(serviceID string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
- func WatchChecks(service, state string, stale bool, token, datacenter string) (*watch.Plan, error)
- func WatchChecksHandler(service, state string, stale bool, token, datacenter string, ...) (wp *watch.Plan, err error)
- func WatchChecksHybridHandler(service, state string, stale bool, token, datacenter string, ...) (wp *watch.Plan, err error)
- func WatchConnectLeaf(service, token, datacenter string) (*watch.Plan, error)
- func WatchConnectLeafHandler(service, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
- func WatchConnectLeafHybridHandler(service, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
- func WatchConnectRoots(token, datacenter string) (*watch.Plan, error)
- func WatchConnectRootsHandler(token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
- func WatchConnectRootsHybridHandler(token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
- func WatchEvent(name, token, datacenter string) (*watch.Plan, error)
- func WatchEventHandler(name, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
- func WatchEventHybridHandler(name, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
- func WatchKey(key string, stale bool, token, datacenter string) (*watch.Plan, error)
- func WatchKeyHandler(key string, stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
- func WatchKeyHybridHandler(key string, stale bool, token, datacenter string, ...) (wp *watch.Plan, err error)
- func WatchKeyPrefix(prefix string, stale bool, token, datacenter string) (*watch.Plan, error)
- func WatchKeyPrefixHandler(prefix string, stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
- func WatchKeyPrefixHybridHandler(prefix string, stale bool, token, datacenter string, ...) (wp *watch.Plan, err error)
- func WatchNodes(stale bool, token, datacenter string) (*watch.Plan, error)
- func WatchNodesHandler(stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
- func WatchNodesHybridHandler(stale bool, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
- func WatchService(service, tag string, passingOnly, stale bool, token, datacenter string) (*watch.Plan, error)
- func WatchServiceHandler(service, tag string, passingOnly, stale bool, token, datacenter string, ...) (wp *watch.Plan, err error)
- func WatchServiceHybridHandler(service, tag string, passingOnly, stale bool, token, datacenter string, ...) (wp *watch.Plan, err error)
- func WatchServiceMultipleTags(service string, tags []string, passingOnly, stale bool, ...) (*watch.Plan, error)
- func WatchServices(stale bool, token, datacenter string) (*watch.Plan, error)
- func WatchServicesHandler(stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
- func WatchServicesHybridHandler(stale bool, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
- type AgentServiceCheckMutator
- type BasicNotifier
- func (nb BasicNotifier) AttachNotificationChannel(id string, ch NotificationChannel) (string, bool)
- func (nb BasicNotifier) AttachNotificationChannels(chs ...NotificationChannel) []NotifierAttachResult
- func (nb BasicNotifier) AttachNotificationHandler(id string, fn NotificationHandler) (string, bool)
- func (nb BasicNotifier) AttachNotificationHandlers(fns ...NotificationHandler) []NotifierAttachResult
- func (nb BasicNotifier) DetachAllNotificationRecipients(wait bool) int
- func (nb BasicNotifier) DetachNotificationRecipient(id string) bool
- func (bn *BasicNotifier) Push(s NotificationSource, ev NotificationEvent, d interface{})
- type Candidate
- func (nb Candidate) AttachNotificationChannel(id string, ch NotificationChannel) (string, bool)
- func (nb Candidate) AttachNotificationChannels(chs ...NotificationChannel) []NotifierAttachResult
- func (nb Candidate) AttachNotificationHandler(id string, fn NotificationHandler) (string, bool)
- func (nb Candidate) AttachNotificationHandlers(fns ...NotificationHandler) []NotifierAttachResult
- func (nb Candidate) DetachAllNotificationRecipients(wait bool) int
- func (nb Candidate) DetachNotificationRecipient(id string) bool
- func (c *Candidate) Elected() bool
- func (c *Candidate) ForeignLeaderKV(ctx context.Context, datacenter string) (*api.KVPair, *api.QueryMeta, error)
- func (c *Candidate) ForeignLeaderSession(ctx context.Context, datacenter string) (*api.SessionEntry, *api.QueryMeta, error)
- func (c *Candidate) ID() string
- func (c *Candidate) LeaderKV(ctx context.Context) (*api.KVPair, *api.QueryMeta, error)
- func (c *Candidate) LeaderSession(ctx context.Context) (*api.SessionEntry, *api.QueryMeta, error)
- func (c *Candidate) Resign() error
- func (c *Candidate) Resigned() bool
- func (c *Candidate) Run() error
- func (c *Candidate) Running() bool
- func (c *Candidate) Session() *ManagedSession
- func (c *Candidate) Shutdown() error
- func (c *Candidate) Shutdowned() bool
- func (c *Candidate) State() CandidateState
- func (c *Candidate) Wait() error
- func (c *Candidate) WaitNotify(ch chan<- error)
- func (c *Candidate) WaitUntil(ctx context.Context) error
- func (c *Candidate) WaitUntilNotify(ctx context.Context, ch chan<- error)
- type CandidateConfig
- type CandidateDefaultLeaderKVValue
- type CandidateLeaderKVValueProvider
- type CandidateState
- type CandidateUpdate
- type Client
- func (c *Client) BuildServiceURL(protocol, serviceName, tag string, passingOnly bool, options *api.QueryOptions) (*url.URL, error)
- func (c *Client) EnsureKey(key string, options *api.QueryOptions) (*api.KVPair, *api.QueryMeta, error)
- func (c *Client) EnsureKeyJSON(key string, options *api.QueryOptions, v interface{}) (*api.QueryMeta, error)
- func (c *Client) EnsureKeyString(key string, options *api.QueryOptions) (string, *api.QueryMeta, error)
- func (c *Client) EnsureService(service, tag string, passingOnly bool, options *api.QueryOptions) (*api.ServiceEntry, *api.QueryMeta, error)
- func (c *Client) EnsureServiceMultipleTags(service string, tags []string, passingOnly bool, options *api.QueryOptions) (*api.ServiceEntry, *api.QueryMeta, error)
- func (c *Client) LocalAddress() string
- func (c *Client) LocalHostname() string
- func (c *Client) LocalNodeAddr() string
- func (c *Client) LocalNodeName() (string, error)
- func (c *Client) ManagedServiceRegister(reg *SimpleServiceRegistration, cfg *ManagedServiceConfig, ...) (*ManagedService, error)
- func (c *Client) PickService(service, tag string, passingOnly bool, options *api.QueryOptions) (*api.ServiceEntry, *api.QueryMeta, error)
- func (c *Client) PickServiceMultipleTags(service string, tags []string, passingOnly bool, options *api.QueryOptions) (*api.ServiceEntry, *api.QueryMeta, error)
- func (c *Client) ServiceByTags(service string, tags []string, tagsOption TagsOption, passingOnly bool, ...) ([]*api.ServiceEntry, *api.QueryMeta, error)
- func (c *Client) SetLocalAddress(myAddr string)
- func (c *Client) SetLocalHostname(myHost string)
- func (c *Client) SimpleServiceRegister(reg *SimpleServiceRegistration) (string, error)
- func (c *Client) WatchAgentService(serviceID string, handler watch.HandlerFunc) (*watch.Plan, error)
- func (c *Client) WatchChecks(service, state string, stale bool, handler watch.HandlerFunc) (*watch.Plan, error)
- func (c *Client) WatchConnectLeaf(service string, handler watch.HandlerFunc) (*watch.Plan, error)
- func (c *Client) WatchConnectRoots(handler watch.HandlerFunc) (*watch.Plan, error)
- func (c *Client) WatchEvent(name string, handler watch.HandlerFunc) (*watch.Plan, error)
- func (c *Client) WatchKey(key string, stale bool, handler watch.HandlerFunc) (*watch.Plan, error)
- func (c *Client) WatchKeyPrefix(prefix string, stale bool, handler watch.HandlerFunc) (*watch.Plan, error)
- func (c *Client) WatchNodes(stale bool, handler watch.HandlerFunc) (*watch.Plan, error)
- func (c *Client) WatchService(service, tag string, passingOnly, stale bool, handler watch.HandlerFunc) (*watch.Plan, error)
- func (c *Client) WatchServices(stale bool, handler watch.HandlerFunc) (*watch.Plan, error)
- type Logger
- type ManagedAgentServiceRegistration
- func (b *ManagedAgentServiceRegistration) AddAliasCheck(service, node string, interval time.Duration, fns ...AgentServiceCheckMutator) *ManagedAgentServiceRegistration
- func (b *ManagedAgentServiceRegistration) AddCheck(check *api.AgentServiceCheck, fns ...AgentServiceCheckMutator) *ManagedAgentServiceRegistration
- func (b *ManagedAgentServiceRegistration) AddDockerCheck(containerID string, shell string, args []string, interval time.Duration, ...) *ManagedAgentServiceRegistration
- func (b *ManagedAgentServiceRegistration) AddGRPCCheck(interval time.Duration, fns ...AgentServiceCheckMutator) *ManagedAgentServiceRegistration
- func (b *ManagedAgentServiceRegistration) AddHTTPCheck(method, scheme, path string, interval time.Duration, ...) *ManagedAgentServiceRegistration
- func (b *ManagedAgentServiceRegistration) AddScriptCheck(args []string, interval time.Duration, fns ...AgentServiceCheckMutator) *ManagedAgentServiceRegistration
- func (b *ManagedAgentServiceRegistration) AddTCPCheck(interval time.Duration, fns ...AgentServiceCheckMutator) *ManagedAgentServiceRegistration
- func (b *ManagedAgentServiceRegistration) AddTTLCheck(originalStatus string, ttl time.Duration, fns ...AgentServiceCheckMutator) *ManagedAgentServiceRegistration
- func (b *ManagedAgentServiceRegistration) Create(cfg *ManagedServiceConfig) (*ManagedService, error)
- func (b *ManagedAgentServiceRegistration) SetID(f string, v ...interface{}) *ManagedAgentServiceRegistration
- type ManagedAgentServiceRegistrationMutator
- type ManagedService
- func (ms *ManagedService) AddTags(tags ...string) (int, error)
- func (ms *ManagedService) AgentService(ctx context.Context) (*api.AgentService, *api.QueryMeta, error)
- func (nb ManagedService) AttachNotificationChannel(id string, ch NotificationChannel) (string, bool)
- func (nb ManagedService) AttachNotificationChannels(chs ...NotificationChannel) []NotifierAttachResult
- func (nb ManagedService) AttachNotificationHandler(id string, fn NotificationHandler) (string, bool)
- func (nb ManagedService) AttachNotificationHandlers(fns ...NotificationHandler) []NotifierAttachResult
- func (ms *ManagedService) CatalogService(ctx context.Context) (*api.CatalogService, *api.QueryMeta, error)
- func (ms *ManagedService) Checks(ctx context.Context) (api.HealthChecks, *api.QueryMeta, error)
- func (ms *ManagedService) Deregister() error
- func (nb ManagedService) DetachAllNotificationRecipients(wait bool) int
- func (nb ManagedService) DetachNotificationRecipient(id string) bool
- func (ms *ManagedService) ForceRefresh() error
- func (ms *ManagedService) LastRefreshed() time.Time
- func (ms *ManagedService) Register() error
- func (ms *ManagedService) RemoveTags(tags ...string) (int, error)
- func (ms *ManagedService) Running() bool
- func (ms *ManagedService) ServiceEntry(ctx context.Context) (*api.ServiceEntry, *api.QueryMeta, error)
- func (ms *ManagedService) ServiceID() string
- func (ms *ManagedService) ServiceName() string
- func (ms *ManagedService) Shutdown() error
- func (ms *ManagedService) Shutdowned() bool
- func (ms *ManagedService) State() ManagedServiceState
- func (ms *ManagedService) Stopped() bool
- type ManagedServiceConfig
- type ManagedServiceState
- type ManagedServiceUpdate
- type ManagedSession
- func (nb ManagedSession) AttachNotificationChannel(id string, ch NotificationChannel) (string, bool)
- func (nb ManagedSession) AttachNotificationChannels(chs ...NotificationChannel) []NotifierAttachResult
- func (nb ManagedSession) AttachNotificationHandler(id string, fn NotificationHandler) (string, bool)
- func (nb ManagedSession) AttachNotificationHandlers(fns ...NotificationHandler) []NotifierAttachResult
- func (nb ManagedSession) DetachAllNotificationRecipients(wait bool) int
- func (nb ManagedSession) DetachNotificationRecipient(id string) bool
- func (ms *ManagedSession) ID() string
- func (ms *ManagedSession) LastRenewed() time.Time
- func (ms *ManagedSession) Name() string
- func (ms *ManagedSession) PushStateNotification()
- func (ms *ManagedSession) RenewInterval() time.Duration
- func (ms *ManagedSession) Run() error
- func (ms *ManagedSession) Running() bool
- func (ms *ManagedSession) SessionEntry(ctx context.Context) (*api.SessionEntry, *api.QueryMeta, error)
- func (ms *ManagedSession) Shutdown() error
- func (ms *ManagedSession) Shutdowned() bool
- func (ms *ManagedSession) State() ManagedSessionState
- func (ms *ManagedSession) Stop() error
- func (ms *ManagedSession) Stopped() bool
- func (ms *ManagedSession) TTL() time.Duration
- func (ms *ManagedSession) TTLBehavior() string
- type ManagedSessionConfig
- type ManagedSessionEntry
- func (b *ManagedSessionEntry) AddCheckNames(checkNames ...string) *ManagedSessionEntry
- func (b *ManagedSessionEntry) Create(cfg *ManagedSessionConfig) (*ManagedSession, error)
- func (b *ManagedSessionEntry) SetName(f string, v ...interface{}) *ManagedSessionEntry
- func (b *ManagedSessionEntry) SetTTL(ttl time.Duration) *ManagedSessionEntry
- type ManagedSessionEntryMutator
- type ManagedSessionState
- type ManagedSessionUpdate
- type Notification
- type NotificationChannel
- type NotificationEvent
- type NotificationHandler
- type NotificationSource
- type Notifier
- type NotifierAttachResult
- type SimpleServiceRegistration
- type SlugParams
- type TagsOption
Constants ¶
const ( ServiceDefaultIDFormat = SlugName + "-" + SlugAddr + "-" + SlugRand ServiceDefaultRefreshInterval = api.ReadableDuration(30 * time.Second) )
const ( SessionMinimumTTL = 10 * time.Second SessionDefaultTTL = 30 * time.Second SessionMaximumTTL = 24 * time.Hour // SessionDefaultNameFormat will be used to create a name for any created ManagedSession instance that did not have // one set in its configured definition SessionDefaultNameFormat = "managed_session_" + SlugNode + "_" + SlugRand // SessionDefaultNodeName is only ever used when: // 1. the connected consul node name could not be determined // 2. os.Hostname() results in an error SessionDefaultNodeName = "LOCAL" )
const ( // EnvConsulLocalAddr is an environment variable you may define that will be used for LocalAddress() results EnvConsulLocalAddr = "CONSUL_LOCAL_ADDR" // EnvConsulLocalInterface is an environment variable you may define to limit the interfaces looped over to find // a RFC1918 address on EnvConsulLocalInterface = "CONSUL_LOCAL_INTERFACE" SlugRand = "!RAND!" SlugName = "!NAME!" SlugAddr = "!ADDR!" SlugNode = "!NODE!" SlugUnix = "!UNIX!" )
Variables ¶
This section is empty.
Functions ¶
func CandidateDefaultLeaderKVValueProvider ¶
CandidateDefaultLeaderKVValueProvider is the default data provider used when none is configured for a given candidate
func IsNotFoundError ¶
IsNotFoundErr performs a simple test to see if the provided error describes a "404 not found" response from an agent
func LazyRandomString ¶
LazyRandomString will create a base62 string with a min-length of 12
func LocalAddress ¶
LocalAddress returns the string output from LocalAddressIP, or the error if there was one.
func LocalAddressIP ¶
LocalAddressIP searches available interfaces (skip loopback) and returns the first private ipv4 address found giving preference to smaller RFC1918 blocks: 192.168.0.0/16 < 172.16.0.0/12 < 10.0.0.0/8
func RandomLocalPort ¶
func RandomLocalPort() int
RandomLocalPort is a very lazy way to ask for a random port from the kernel. Probably don't rely on this.
shamelessly copy-pasted from and old version of consul test util
func ReplaceSlugs ¶
func ReplaceSlugs(s string, p SlugParams) string
ReplaceSlugs does just that based on the provided input
func SpecificCatalogService ¶
func SpecificCatalogService(serviceID string, svcs []*api.CatalogService) (*api.CatalogService, bool)
SpecificCatalogService attempts to find a specific service's entry from the catalog endpoint
func SpecificChecks ¶
func SpecificChecks(serviceID string, checks api.HealthChecks) api.HealthChecks
SpecificChecks attempts to find a specific service's checks from the health check endpoint
func SpecificServiceEntry ¶
func SpecificServiceEntry(serviceID string, svcs []*api.ServiceEntry) (*api.ServiceEntry, bool)
SpecificServiceEntry attempts to find a specific service's entry from the health endpoint
func WatchAgentService ¶
WatchAgentService wraps the creation of a "agent_service" plan
func WatchAgentServiceHandler ¶
func WatchAgentServiceHandler(serviceID string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
WatchAgentServiceHandler wraps the creation of a "connect_proxy_config" plan, additionally setting an index handler
func WatchAgentServiceHybridHandler ¶
func WatchAgentServiceHybridHandler(serviceID string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
WatchAgentServiceHybridHandler wraps the creation of a "connect_proxy_config" plan, additionally setting a hash handler
func WatchChecks ¶
WatchChecks wraps the creation of a "checks" plan
func WatchChecksHandler ¶
func WatchChecksHandler(service, state string, stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
WatchChecksHandler wraps the creation of a "checks" plan, additionally setting an index handler
func WatchChecksHybridHandler ¶
func WatchChecksHybridHandler(service, state string, stale bool, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
WatchChecksHybridHandler wraps the creation of a "checks" plan, additionally setting a hash handler
func WatchConnectLeaf ¶
WatchConnectLeaf wraps the creation of a "connect_leaf" plan
func WatchConnectLeafHandler ¶
func WatchConnectLeafHandler(service, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
WatchConnectLeafHandler wraps the creation of a "connect_leaf" plan, additionally setting an index handler
func WatchConnectLeafHybridHandler ¶
func WatchConnectLeafHybridHandler(service, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
WatchConnectLeafHybridHandler wraps the creation of a "connect_leaf" plan, additionally setting a hash handler
func WatchConnectRoots ¶
WatchConnectRoots wraps the creation of a "connect_roots" plan
func WatchConnectRootsHandler ¶
func WatchConnectRootsHandler(token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
WatchConnectRootsHandler wraps the creation of a "connect_roots" plan, additionally setting an index handler
func WatchConnectRootsHybridHandler ¶
func WatchConnectRootsHybridHandler(token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
WatchConnectRootsHybridHandler wraps the creation of a "connect_roots" plan, additionally setting a hash handler
func WatchEvent ¶
WatchEvent wraps the creation of an "event" plan
func WatchEventHandler ¶
func WatchEventHandler(name, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
WatchEventHandler wraps the creation of an "event" plan, additionally setting an index handler
func WatchEventHybridHandler ¶
func WatchEventHybridHandler(name, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
WatchEventHybridHandler wraps the creation of an "event" plan, additionally setting a hash handler
func WatchKeyHandler ¶
func WatchKeyHandler(key string, stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
WatchKeyHandler wraps the creation of a "key" plan, additionally assigning an index handler func
func WatchKeyHybridHandler ¶
func WatchKeyHybridHandler(key string, stale bool, token, datacenter string, hybridHandler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
WatchKeyHybridHandler wraps the creation of a "key" plan, additionally assigning hybrid (hash) handler func
func WatchKeyPrefix ¶
WatchKeyPrefix wraps the creation of a "keyprefix" plan
func WatchKeyPrefixHandler ¶
func WatchKeyPrefixHandler(prefix string, stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
WatchKeyPrefixHandler wraps the creation of a "keyprefix" plan, additionally assigning an index handler func
func WatchKeyPrefixHybridHandler ¶
func WatchKeyPrefixHybridHandler(prefix string, stale bool, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
WatchKeyPrefixHybridHandler wraps the creation of a "keyprefix" plan, additionally assigning a hash handler func
func WatchNodes ¶
WatchNodes wraps the creation of a "nodes" plan
func WatchNodesHandler ¶
func WatchNodesHandler(stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
WatchNodesHandler wraps the creation of a "nodes" plan, additionally assigning an index handler
func WatchNodesHybridHandler ¶
func WatchNodesHybridHandler(stale bool, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
WatchNodesHybridHandler wraps the creation of a "nodes" plan, additionally assigning a hash handler
func WatchService ¶
func WatchService(service, tag string, passingOnly, stale bool, token, datacenter string) (*watch.Plan, error)
WatchService wraps the creation of a "service" plan
func WatchServiceHandler ¶
func WatchServiceHandler(service, tag string, passingOnly, stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
WatchServiceHandler wraps the creation of a "service" plan, additionally setting an index handler
func WatchServiceHybridHandler ¶
func WatchServiceHybridHandler(service, tag string, passingOnly, stale bool, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
WatchServiceHybridHandler wraps the creation of a "service" plan, additionally setting a hash handler
func WatchServices ¶
WatchServices wraps the creation of a "services" plan
func WatchServicesHandler ¶
func WatchServicesHandler(stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error)
WatchServicesHandler wraps the creation of a "services" plan, additionally assigning an index handler
func WatchServicesHybridHandler ¶
func WatchServicesHybridHandler(stale bool, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error)
WatchServicesHybridHandler wraps the creation of a "services" plan, additionally assigning a hash handler
Types ¶
type AgentServiceCheckMutator ¶
type AgentServiceCheckMutator func(*api.AgentServiceCheck)
AgentServiceCheckMutator defines a callback that may mutate a new AgentServiceCheck instance
type BasicNotifier ¶
type BasicNotifier struct {
// contains filtered or unexported fields
}
BasicNotifier is the base implementation of a Notifier
func NewBasicNotifier ¶
func NewBasicNotifier(log Logger, debug bool) *BasicNotifier
NewBasicNotifier returns the default Notifier implementation
func (BasicNotifier) AttachNotificationChannel ¶
func (nb BasicNotifier) AttachNotificationChannel(id string, ch NotificationChannel) (string, bool)
AttachNotificationChannel will register a new channel for notifications to be pushed to
func (BasicNotifier) AttachNotificationChannels ¶
func (nb BasicNotifier) AttachNotificationChannels(chs ...NotificationChannel) []NotifierAttachResult
AttachNotificationChannels will attempt to attach multiple channels at once
func (BasicNotifier) AttachNotificationHandler ¶
func (nb BasicNotifier) AttachNotificationHandler(id string, fn NotificationHandler) (string, bool)
AttachNotificationHandler immediately adds the provided handler to the list of handlers to be called per notification
func (BasicNotifier) AttachNotificationHandlers ¶
func (nb BasicNotifier) AttachNotificationHandlers(fns ...NotificationHandler) []NotifierAttachResult
AttachNotificationHandlers allows you to attach 1 or more notification handlers at a time
func (BasicNotifier) DetachAllNotificationRecipients ¶
DetachAllNotificationRecipients immediately clears all attached recipients, returning the count of those previously attached.
func (BasicNotifier) DetachNotificationRecipient ¶
DetachNotificationRecipient immediately removes the provided recipient from receiving any new notifications, returning true if a recipient was found with the provided id
func (*BasicNotifier) Push ¶
func (bn *BasicNotifier) Push(s NotificationSource, ev NotificationEvent, d interface{})
Push will immediately send a new notification to all currently registered recipients
type Candidate ¶
type Candidate struct {
// contains filtered or unexported fields
}
Candidate represents an extension to the ManagedSession type that will additionally attempt to apply the session to a specific LeaderKV key. This can then be used to facilitate "leader election" by way of the "leader" being the Candidate who's session is locking the target key.
func NewCandidate ¶
func NewCandidate(conf *CandidateConfig) (*Candidate, error)
func (Candidate) AttachNotificationChannel ¶
func (nb Candidate) AttachNotificationChannel(id string, ch NotificationChannel) (string, bool)
AttachNotificationChannel will register a new channel for notifications to be pushed to
func (Candidate) AttachNotificationChannels ¶
func (nb Candidate) AttachNotificationChannels(chs ...NotificationChannel) []NotifierAttachResult
AttachNotificationChannels will attempt to attach multiple channels at once
func (Candidate) AttachNotificationHandler ¶
func (nb Candidate) AttachNotificationHandler(id string, fn NotificationHandler) (string, bool)
AttachNotificationHandler immediately adds the provided handler to the list of handlers to be called per notification
func (Candidate) AttachNotificationHandlers ¶
func (nb Candidate) AttachNotificationHandlers(fns ...NotificationHandler) []NotifierAttachResult
AttachNotificationHandlers allows you to attach 1 or more notification handlers at a time
func (Candidate) DetachAllNotificationRecipients ¶
DetachAllNotificationRecipients immediately clears all attached recipients, returning the count of those previously attached.
func (Candidate) DetachNotificationRecipient ¶
DetachNotificationRecipient immediately removes the provided recipient from receiving any new notifications, returning true if a recipient was found with the provided id
func (*Candidate) Elected ¶
Elected will return true if this candidate's session is "locking" the kv
func (*Candidate) ForeignLeaderKV ¶
func (c *Candidate) ForeignLeaderKV(ctx context.Context, datacenter string) (*api.KVPair, *api.QueryMeta, error)
ForeignLeaderKV attempts to return the LeaderKV being used to control leader election in the specified datacenter
func (*Candidate) ForeignLeaderSession ¶
func (c *Candidate) ForeignLeaderSession(ctx context.Context, datacenter string) (*api.SessionEntry, *api.QueryMeta, error)
ForeignLeaderSession will attempt to locate the leader's session entry in a datacenter of your choosing
func (*Candidate) LeaderKV ¶
LeaderKV attempts to return the LeaderKV being used to control leader election in the local datacenter
func (*Candidate) LeaderSession ¶
LeaderSession will attempt to locate the leader's session entry in your local agent's datacenter
func (*Candidate) Resigned ¶
Resigned returns true if the current state of the Candidate is resigned
func (*Candidate) Run ¶
Run will enter this candidate into the election pool. If the candidate is already running this does nothing.
func (*Candidate) Session ¶
func (c *Candidate) Session() *ManagedSession
Session returns the underlying ManagedSession instance used by this Candidate
func (*Candidate) Shutdown ¶
Shutdown will remove this candidate from the election pool and render it defunct
func (*Candidate) Shutdowned ¶
Shutdowned returns true if the current state of the candidate is shutdowned
func (*Candidate) State ¶
func (c *Candidate) State() CandidateState
State returns the current state of this Candidate
func (*Candidate) WaitNotify ¶
WaitNotify accepts a channel that will have the end result of .Wait() pushed onto it
type CandidateConfig ¶
type CandidateConfig struct { ManagedSessionConfig // KVKey [required] // // Must be the key to attempt to acquire a session lock on. This key must be considered ephemeral, and not contain // anything you don't want overwritten / destroyed. KVKey string // KVDataProvider [optional] // // Optionally provide a callback func that returns a []byte to be used as the data value when a running Candidate // acquires the lock (i.e. is "elected"). Calls to this method MUST NOT be taken as a sign of the provided // candidate having been elected. It ONLY indicates that the candidate is ATTEMPTING to be elected. KVDataProvider CandidateLeaderKVValueProvider // ID [suggested] // // Should be a unique identifier for this specific Candidate that makes sense within the scope of your // implementation. If left blank it will attempt to use the local IP address, otherwise a random string will be // generated. This is a way to identify which Candidate is holding the lock. ID string // Debug [optional] // // Enables debug logging output. If true here but false in ManagedSessionConfig instance only Candidate will have // debug logging enabled and vice versa. Debug bool // Logger [optional] // // Logger for logging. No logger means no logging. Allows for a separate logger instance to be used from the // underlying ManagedSession instance. Logger Logger }
CandidateConfig describes a Candidate
type CandidateDefaultLeaderKVValue ¶
type CandidateDefaultLeaderKVValue struct { LeaderID string `json:"leader_id"` SessionID string `json:"session_id"` }
CandidateDefaultLeaderKVValue is the body of the acquired LeaderKV when no CandidateLeaderKVValueProvider is provided during candidate configuration
type CandidateLeaderKVValueProvider ¶
CandidateLeaderKVValueProvider is called whenever a running Candidate attempts to acquire the lock on the defined kv key. The resulting []byte is used as the data payload, and may be whatever you wish.
A call to this func does NOT mean that the provided candidate IS the leader, it means that it is ATTEMPTING TO BECOME the leader.
type CandidateState ¶
type CandidateState uint8
const ( // 0x10 - 0x1f CandidateStateResigned CandidateState = 0x10 CandidateStateRunning CandidateState = 0x11 CandidateStateShutdowned CandidateState = 0x12 )
func (CandidateState) String ¶
func (s CandidateState) String() string
type CandidateUpdate ¶
type CandidateUpdate struct { // ID will be the ID of the Candidate pushing this update ID string `json:"id"` // Elected tracks whether this specific candidate has been elected Elected bool `json:"elected"` // State tracks the current state of this candidate State CandidateState `json:"state"` // Error will be defined if there an error associated with the notification Error error `json:"error"` }
CandidateUpdate is the value of .Data in all Notification pushes from a Candidate
type Client ¶
Client is a thin wrapper around the base Consul API client with some convenience methods added
func NewDefaultClient ¶
NewDefaultClient creates a new client with default configuration values
func NewDefaultNonPooledClient ¶
NewDefaultNonPooledClient creates a new client with default configuration values and a non-pooled http client
func (*Client) BuildServiceURL ¶
func (c *Client) BuildServiceURL(protocol, serviceName, tag string, passingOnly bool, options *api.QueryOptions) (*url.URL, error)
BuildServiceURL will attempt to locate a healthy instance of the specified service name + tag combination, then attempt to construct a *net.URL from the resulting service information
func (*Client) EnsureKey ¶
func (c *Client) EnsureKey(key string, options *api.QueryOptions) (*api.KVPair, *api.QueryMeta, error)
EnsureKey will fetch a key/value and ensure the key is present. The value may still be empty.
func (*Client) EnsureKeyJSON ¶
func (c *Client) EnsureKeyJSON(key string, options *api.QueryOptions, v interface{}) (*api.QueryMeta, error)
EnsureKeyJSON will attempt to unmarshal the kvp value into the provided type
func (*Client) EnsureKeyString ¶
func (c *Client) EnsureKeyString(key string, options *api.QueryOptions) (string, *api.QueryMeta, error)
EnsureKeyString is a convenience method that will typecast the kvp.Value byte slice to a string for you, if there were no errors.
func (*Client) EnsureService ¶
func (c *Client) EnsureService(service, tag string, passingOnly bool, options *api.QueryOptions) (*api.ServiceEntry, *api.QueryMeta, error)
EnsureService will return an error for an actual client error or if no service was found using the provided criteria
func (*Client) EnsureServiceMultipleTags ¶
func (c *Client) EnsureServiceMultipleTags(service string, tags []string, passingOnly bool, options *api.QueryOptions) (*api.ServiceEntry, *api.QueryMeta, error)
EnsureServiceMultipleTags will return an error for an actual client error or if no service was found using the provided criteria
func (*Client) LocalAddress ¶
LocalAddress returns either the self-determine or set IP address of our host
func (*Client) LocalHostname ¶
LocalHostname returns either the self-determined or set name of our host
func (*Client) LocalNodeAddr ¶ added in v2.3.0
LocalNodeAddr returns the address of the Consul Node this client is connected to
func (*Client) LocalNodeName ¶
LocalNodeName returns the name of the Consul Node this client is connected to
func (*Client) ManagedServiceRegister ¶
func (c *Client) ManagedServiceRegister(reg *SimpleServiceRegistration, cfg *ManagedServiceConfig, fns ...ManagedAgentServiceRegistrationMutator) (*ManagedService, error)
ManagedServiceRegister creates a new ManagedService instance from a SimpleServiceRegistration type
You are not required to provide a *ManagedServiceConfig instance to this method, and you are
func (*Client) PickService ¶
func (c *Client) PickService(service, tag string, passingOnly bool, options *api.QueryOptions) (*api.ServiceEntry, *api.QueryMeta, error)
PickService will attempt to locate any registered service with a name + tag combination and return one at random from the resulting list
func (*Client) PickServiceMultipleTags ¶
func (c *Client) PickServiceMultipleTags(service string, tags []string, passingOnly bool, options *api.QueryOptions) (*api.ServiceEntry, *api.QueryMeta, error)
PickServiceMultipleTags will attempt to locate any registered service with a name + tags combination and return one at random from the resulting list
func (*Client) ServiceByTags ¶
func (c *Client) ServiceByTags(service string, tags []string, tagsOption TagsOption, passingOnly bool, options *api.QueryOptions) ([]*api.ServiceEntry, *api.QueryMeta, error)
ServiceByTags - this wraps the consul Health().Service() call, adding the tagsOption parameter and accepting a slice of tags. tagsOption should be one of the following:
TagsAll - this will return only services that have all the specified tags present. TagsExactly - like TagsAll, but will return only services that match exactly the tags specified, no more. TagsAny - this will return services that match any of the tags specified. TagsExclude - this will return services don't have any of the tags specified.
func (*Client) SetLocalAddress ¶
SetLocalAddress allows you to manually specify the IP address of our host
func (*Client) SetLocalHostname ¶
SetLocalHostname allows you to to manually specify the name of our host. This does NOT update the host's name.
func (*Client) SimpleServiceRegister ¶
func (c *Client) SimpleServiceRegister(reg *SimpleServiceRegistration) (string, error)
SimpleServiceRegister is a helper method to ease consul service registration
func (*Client) WatchAgentService ¶
func (c *Client) WatchAgentService(serviceID string, handler watch.HandlerFunc) (*watch.Plan, error)
WatchAgentService will attempt to create a "connect_proxy_config" watch plan based on existing client configuration
func (*Client) WatchChecks ¶
func (c *Client) WatchChecks(service, state string, stale bool, handler watch.HandlerFunc) (*watch.Plan, error)
WatchChecks will attempt to create a "checks" watch plan based on existing client configuration
func (*Client) WatchConnectLeaf ¶
WatchConnectLeaf will attempt to create a "connect_leaf" watch plan based on existing client configuration
func (*Client) WatchConnectRoots ¶
WatchConnectRoots will attempt to create a "connect_roots" watch plan based on existing client configuration
func (*Client) WatchEvent ¶
WatchEvent will attempt to create an "event" watch plan based on existing client configuration
func (*Client) WatchKey ¶
WatchKey will attempt to create a "key" watch plan based on existing client configuration
func (*Client) WatchKeyPrefix ¶
func (c *Client) WatchKeyPrefix(prefix string, stale bool, handler watch.HandlerFunc) (*watch.Plan, error)
WatchKeyPrefix will attempt to create a "keyprefix" watch plan based on existing client configuration
func (*Client) WatchNodes ¶
WatchNodes will attempt to create a "nodes" watch plan based on existing client configuration
func (*Client) WatchService ¶
func (c *Client) WatchService(service, tag string, passingOnly, stale bool, handler watch.HandlerFunc) (*watch.Plan, error)
WatchService will attempt to create a "service" watch plan based on existing client configuration
func (*Client) WatchServices ¶
WatchServices will attempt to create a "services" watch plan based on existing client configuration
type ManagedAgentServiceRegistration ¶
type ManagedAgentServiceRegistration struct {
api.AgentServiceRegistration
}
ManagedAgentServiceRegistration is a thin helper that provides guided construction of an AgentServiceRegistration, resulting in a ManagedService instance once built
func NewBareManagedAgentServiceRegistration ¶
func NewBareManagedAgentServiceRegistration(name string, port int, fns ...ManagedAgentServiceRegistrationMutator) *ManagedAgentServiceRegistration
NewBareManagedAgentServiceRegistration constructs a new builder with the name, address, and port fields defined. The Address value is guessed using LocalAddress() and may be overwritten at any time.
func NewManagedAgentServiceRegistration ¶
func NewManagedAgentServiceRegistration(base *api.AgentServiceRegistration, fns ...ManagedAgentServiceRegistrationMutator) *ManagedAgentServiceRegistration
NewManagedAgentServiceRegistration constructs a new builder based on an existing AgentServiceRegistration instance. It also ensures that all slice and map fields (Tags, Checks, TaggedAddresses, and Meta) are non-nil.
As a caution, the provided base is stored as-is. If you modify the base registration type outside of the methods provided by the returned type, the ttlBehavior is entirely undefined.
func (*ManagedAgentServiceRegistration) AddAliasCheck ¶
func (b *ManagedAgentServiceRegistration) AddAliasCheck(service, node string, interval time.Duration, fns ...AgentServiceCheckMutator) *ManagedAgentServiceRegistration
AddAliasCheck compiles and adds an alias service check.
func (*ManagedAgentServiceRegistration) AddCheck ¶
func (b *ManagedAgentServiceRegistration) AddCheck(check *api.AgentServiceCheck, fns ...AgentServiceCheckMutator) *ManagedAgentServiceRegistration
AddCheck will add a new check to the builder after processing all provided mutators
func (*ManagedAgentServiceRegistration) AddDockerCheck ¶
func (b *ManagedAgentServiceRegistration) AddDockerCheck(containerID string, shell string, args []string, interval time.Duration, fns ...AgentServiceCheckMutator) *ManagedAgentServiceRegistration
AddDockerCheck compiles and adds a new Docker container service check.
func (*ManagedAgentServiceRegistration) AddGRPCCheck ¶
func (b *ManagedAgentServiceRegistration) AddGRPCCheck(interval time.Duration, fns ...AgentServiceCheckMutator) *ManagedAgentServiceRegistration
AddGRPCCheck compiles and adds a gRPC service check based upon the address and port originally configured with the builder.
func (*ManagedAgentServiceRegistration) AddHTTPCheck ¶
func (b *ManagedAgentServiceRegistration) AddHTTPCheck(method, scheme, path string, interval time.Duration, fns ...AgentServiceCheckMutator) *ManagedAgentServiceRegistration
AddHTTPCheck compiles and adds a new HTTP service check based upon the address and port set for the service
func (*ManagedAgentServiceRegistration) AddScriptCheck ¶
func (b *ManagedAgentServiceRegistration) AddScriptCheck(args []string, interval time.Duration, fns ...AgentServiceCheckMutator) *ManagedAgentServiceRegistration
AddScriptCheck compiles and adds a new script service check.
func (*ManagedAgentServiceRegistration) AddTCPCheck ¶
func (b *ManagedAgentServiceRegistration) AddTCPCheck(interval time.Duration, fns ...AgentServiceCheckMutator) *ManagedAgentServiceRegistration
AddTCPCheck compiles and adds a new TCP service check based upon the address and port set for the service.
func (*ManagedAgentServiceRegistration) AddTTLCheck ¶
func (b *ManagedAgentServiceRegistration) AddTTLCheck(originalStatus string, ttl time.Duration, fns ...AgentServiceCheckMutator) *ManagedAgentServiceRegistration
AddTTLCheck compiles and adds a new TTL service check.
func (*ManagedAgentServiceRegistration) Create ¶
func (b *ManagedAgentServiceRegistration) Create(cfg *ManagedServiceConfig) (*ManagedService, error)
Create attempts to first register the configured service with the desired consul agent, then constructs a ManagedService instance for you to use.
If no ID was specified before this method is called, one will be randomly generated for you.
func (*ManagedAgentServiceRegistration) SetID ¶
func (b *ManagedAgentServiceRegistration) SetID(f string, v ...interface{}) *ManagedAgentServiceRegistration
SetID set's the service's ID to the provided format string with values. There are a few additional replacements you may take advantage of:
- !RAND! will be replaced with a unique 12 character random string
- !NAME! will be replaced with the service's name
- !ADDR! will be replaced with the service's address
Note: If you have not previously set an address or name, the slugs will be replaced with empty values
Order of operation:
- fmt.Sprintf(f, v...)
- All !RAND! are replaced
- All !NAME! are replaced
- All !ADDR! are replaced
type ManagedAgentServiceRegistrationMutator ¶
type ManagedAgentServiceRegistrationMutator func(*ManagedAgentServiceRegistration)
ManagedAgentServiceRegistrationMutator defines a callback that may mutate a new ManagedAgentServiceRegistration instance
type ManagedService ¶
type ManagedService struct {
// contains filtered or unexported fields
}
ManagedService
This type is a wrapper around an existing Consul agent service. It provides several wrappers to make managing the lifecycle of a processes' service registration easier.
func NewManagedService ¶
func NewManagedService(cfg *ManagedServiceConfig) (*ManagedService, error)
NewManagedService creates a new ManagedService instance.
func (*ManagedService) AddTags ¶
func (ms *ManagedService) AddTags(tags ...string) (int, error)
AddTags attempts to add one or more tags to the service registration in consul, if and only if EnableTagOverride was enabled when the service was registered.
Returns:
- count of tags added
- error, if unsuccessful
If no tags were provided or the provided list of tags are already present on the service a 0, nil will be returned.
func (*ManagedService) AgentService ¶
func (ms *ManagedService) AgentService(ctx context.Context) (*api.AgentService, *api.QueryMeta, error)
AgentService attempts to fetch the current AgentService entry for this ManagedService using Agent().Service()
func (ManagedService) AttachNotificationChannel ¶
func (nb ManagedService) AttachNotificationChannel(id string, ch NotificationChannel) (string, bool)
AttachNotificationChannel will register a new channel for notifications to be pushed to
func (ManagedService) AttachNotificationChannels ¶
func (nb ManagedService) AttachNotificationChannels(chs ...NotificationChannel) []NotifierAttachResult
AttachNotificationChannels will attempt to attach multiple channels at once
func (ManagedService) AttachNotificationHandler ¶
func (nb ManagedService) AttachNotificationHandler(id string, fn NotificationHandler) (string, bool)
AttachNotificationHandler immediately adds the provided handler to the list of handlers to be called per notification
func (ManagedService) AttachNotificationHandlers ¶
func (nb ManagedService) AttachNotificationHandlers(fns ...NotificationHandler) []NotifierAttachResult
AttachNotificationHandlers allows you to attach 1 or more notification handlers at a time
func (*ManagedService) CatalogService ¶
func (ms *ManagedService) CatalogService(ctx context.Context) (*api.CatalogService, *api.QueryMeta, error)
CatalogService attempts to fetch the current CatalogService entry for this ManagedService using Catalog().Service()
func (*ManagedService) Checks ¶
func (ms *ManagedService) Checks(ctx context.Context) (api.HealthChecks, *api.QueryMeta, error)
Checks returns a list of all the checks registered to this specific service
func (*ManagedService) Deregister ¶
func (ms *ManagedService) Deregister() error
Deregister stops internal maintenance routines and removes the managed service from the connected consul agent
func (ManagedService) DetachAllNotificationRecipients ¶
DetachAllNotificationRecipients immediately clears all attached recipients, returning the count of those previously attached.
func (ManagedService) DetachNotificationRecipient ¶
DetachNotificationRecipient immediately removes the provided recipient from receiving any new notifications, returning true if a recipient was found with the provided id
func (*ManagedService) ForceRefresh ¶
func (ms *ManagedService) ForceRefresh() error
ForceRefresh attempts an immediate internal state refresh, blocking until attempt has been completed.
func (*ManagedService) LastRefreshed ¶
func (ms *ManagedService) LastRefreshed() time.Time
LastRefreshed is the last time the internal state of the managed service was last updated
func (*ManagedService) Register ¶
func (ms *ManagedService) Register() error
Register can be used to re-start this managed service instance if it was previously deregistered
func (*ManagedService) RemoveTags ¶
func (ms *ManagedService) RemoveTags(tags ...string) (int, error)
RemoveTags attempts to remove one or more tags from the service registration in consul, if and only if EnableTagOverride was enabled when the service was registered.
Returns:
- count of tags removed
- error, if unsuccessful
If no tags were provided or none of the tags in the list were present on the service, a 0, nil will be returned.
func (*ManagedService) Running ¶
func (ms *ManagedService) Running() bool
Running returns true if state is "running"
func (*ManagedService) ServiceEntry ¶
func (ms *ManagedService) ServiceEntry(ctx context.Context) (*api.ServiceEntry, *api.QueryMeta, error)
ServiceEntry attempts to fetch the current ServiceEntry entry for this ManagedService using Health().Service()
func (*ManagedService) ServiceID ¶
func (ms *ManagedService) ServiceID() string
ServiceID returns the ID of the service being managed
func (*ManagedService) ServiceName ¶
func (ms *ManagedService) ServiceName() string
ServiceName returns the name of the service being managed
func (*ManagedService) Shutdown ¶
func (ms *ManagedService) Shutdown() error
Shutdown stops internal maintenance routines and removes the managed service from the connected consul agent. Once shutdown, the managed service is considered defunct.
func (*ManagedService) Shutdowned ¶
func (ms *ManagedService) Shutdowned() bool
Shutdowned returns true if state is "stopped"
func (*ManagedService) State ¶
func (ms *ManagedService) State() ManagedServiceState
State returns the current state of this managed service
func (*ManagedService) Stopped ¶
func (ms *ManagedService) Stopped() bool
Stopped returns true if state is "stopped"
type ManagedServiceConfig ¶
type ManagedServiceConfig struct { // ID [required] // // ID of service to fetch to turn into a managed service ID string // BaseChecks [optional] (recommended) // // These are the base service checks that will be re-registered with the service should it be removed externally // from the node the service was registered to. // // This will most likely be removed in the future once https://github.com/hashicorp/consul/issues/1680 is finally // implemented, but for now is necessary if you wish for your service to automatically have its health checks // re-registered BaseChecks api.AgentServiceChecks // RefreshInterval [optional] // // Optionally specify a refresh renewInterval. Defaults to value of ServiceDefaultRefreshInterval. RefreshInterval api.ReadableDuration // QueryOptions [optional] // // Options to use whenever making a read api query. This will be shallow copied per internal request made. QueryOptions *api.QueryOptions // WriteOptions [optional] // // Options to use whenever making a write api query. This will be shallow copied per internal request made. WriteOptions *api.WriteOptions // RequestTTL [optional] // // Optionally specify a TTL to pass to internal API requests. Defaults to 2 seconds RequestTTL time.Duration // Logger [optional] // // Optionally specify a logger. No logging will take place if one is not provided Logger Logger // Debug [optional] // // If true, will enable debug-level logging if a logger is provided Debug bool // Client [optional] // // Optionally provide a Consul client instance to use. If one is not defined, a new one will be created with // default configuration values. Client *api.Client }
ManagedServiceConfig describes the basis for a new ManagedService instance
type ManagedServiceState ¶
type ManagedServiceState uint8
const ( ManagedServiceStateStopped ManagedServiceState = 0x20 ManagedServiceStateRunning ManagedServiceState = 0x21 ManagedServiceStateShutdowned ManagedServiceState = 0x22 )
func (ManagedServiceState) String ¶
func (s ManagedServiceState) String() string
type ManagedServiceUpdate ¶
type ManagedServiceUpdate struct { ServiceID string `json:"service_id"` ServiceName string `json:"service_name"` LastRefreshed time.Time `json:"last_refreshed"` Error error `json:"error"` }
ManagedServiceUpdate is the value of .Data in all Notification pushes from a ManagedService
type ManagedSession ¶
type ManagedSession struct {
// contains filtered or unexported fields
}
ManagedSession
func NewManagedSession ¶
func NewManagedSession(conf *ManagedSessionConfig) (*ManagedSession, error)
NewManagedSession attempts to create a managed session instance for your immediate use.
func (ManagedSession) AttachNotificationChannel ¶
func (nb ManagedSession) AttachNotificationChannel(id string, ch NotificationChannel) (string, bool)
AttachNotificationChannel will register a new channel for notifications to be pushed to
func (ManagedSession) AttachNotificationChannels ¶
func (nb ManagedSession) AttachNotificationChannels(chs ...NotificationChannel) []NotifierAttachResult
AttachNotificationChannels will attempt to attach multiple channels at once
func (ManagedSession) AttachNotificationHandler ¶
func (nb ManagedSession) AttachNotificationHandler(id string, fn NotificationHandler) (string, bool)
AttachNotificationHandler immediately adds the provided handler to the list of handlers to be called per notification
func (ManagedSession) AttachNotificationHandlers ¶
func (nb ManagedSession) AttachNotificationHandlers(fns ...NotificationHandler) []NotifierAttachResult
AttachNotificationHandlers allows you to attach 1 or more notification handlers at a time
func (ManagedSession) DetachAllNotificationRecipients ¶
DetachAllNotificationRecipients immediately clears all attached recipients, returning the count of those previously attached.
func (ManagedSession) DetachNotificationRecipient ¶
DetachNotificationRecipient immediately removes the provided recipient from receiving any new notifications, returning true if a recipient was found with the provided id
func (*ManagedSession) ID ¶
func (ms *ManagedSession) ID() string
ID returns the is of the session as it exists in consul. This value will be empty until the session has been initialized, and then may become empty later if the session is removed.
func (*ManagedSession) LastRenewed ¶
func (ms *ManagedSession) LastRenewed() time.Time
LastRenewed returns the last point at which the TTL was successfully reset
func (*ManagedSession) Name ¶
func (ms *ManagedSession) Name() string
Name returns the name of the session as it exists in consul. This value will be empty until the session has been initialized, and then may become empty later if the session is removed.
func (*ManagedSession) PushStateNotification ¶
func (ms *ManagedSession) PushStateNotification()
PushStateNotification will immediate push the current managed session state to all attached notification recipients
func (*ManagedSession) RenewInterval ¶
func (ms *ManagedSession) RenewInterval() time.Duration
RenewInterval is the renewInterval at which a TTL reset will be attempted
func (*ManagedSession) Run ¶
func (ms *ManagedSession) Run() error
Run immediately starts attempting to acquire a session lock on the configured kv key
func (*ManagedSession) Running ¶
func (ms *ManagedSession) Running() bool
Running returns true so long as the internal session state is "running"
func (*ManagedSession) SessionEntry ¶
func (ms *ManagedSession) SessionEntry(ctx context.Context) (*api.SessionEntry, *api.QueryMeta, error)
SessionEntry attempts to immediately pull the latest state of the upstream session from Consul
func (*ManagedSession) Shutdown ¶
func (ms *ManagedSession) Shutdown() error
Shutdown will immediately render this managed session defunct
func (*ManagedSession) Shutdowned ¶
func (ms *ManagedSession) Shutdowned() bool
Shutdowned returns true if the current state of the session is "shutdowned"
func (*ManagedSession) State ¶
func (ms *ManagedSession) State() ManagedSessionState
State returns the current running state of the managed session
func (*ManagedSession) Stop ¶
func (ms *ManagedSession) Stop() error
Stop immediately attempts to cease session management
func (*ManagedSession) Stopped ¶
func (ms *ManagedSession) Stopped() bool
Stopped returns true if the current state of the session is "stopped"
func (*ManagedSession) TTL ¶
func (ms *ManagedSession) TTL() time.Duration
TTL is the timeout limit for this session before which a refresh must happen, or the configured TTLBehavior will take place
func (*ManagedSession) TTLBehavior ¶
func (ms *ManagedSession) TTLBehavior() string
TTLBehavior is the action that will take place if the TTL is allowed to expire
type ManagedSessionConfig ¶
type ManagedSessionConfig struct { // Definition [suggested] // // This is the base definition of the session you wish to have managed by a ManagedSession instance. It must // contain all necessary values to build and re-build the session as you see fit, as all values other than ID will // be used per session create attempt. // // If left blank, default values will be used for Name and TTL Definition *api.SessionEntry // StartImmediately [optional] // // If true, the session will be immediately ran with this context StartImmediately bool // QueryOptions [optional] // // Options to use whenever making a read api query. This will be shallow copied per internal request made. QueryOptions *api.QueryOptions // WriteOptions [optional] // // Options to use whenever making a write api query. This will be shallow copied per internal request made. WriteOptions *api.WriteOptions // RequestTTL [optional] // // Optionally specify a TTL to pass to internal API requests. Defaults to 2 seconds RequestTTL time.Duration // Logger [optional] // // Optionally specify a logger to use. No logging will take place if left empty Logger Logger // Debug [optional] // // Enables debug-level logging Debug bool // Client [optional] // // API client to use for managing this session. If left empty, a new one will be created using api.DefaultConfig() Client *api.Client }
ManagedSessionConfig describes a ManagedSession
type ManagedSessionEntry ¶
type ManagedSessionEntry struct {
api.SessionEntry
}
ManagedSessionEntry is a thin wrapper that provides guided construction to a SessionEntry, resulting in a ManagedSession instance once built
func NewManagedSessionEntry ¶
func NewManagedSessionEntry(base *api.SessionEntry, fns ...ManagedSessionEntryMutator) *ManagedSessionEntry
NewManagedSessionEntry creates a new
func (*ManagedSessionEntry) AddCheckNames ¶
func (b *ManagedSessionEntry) AddCheckNames(checkNames ...string) *ManagedSessionEntry
AddCheckNames adds the provided list of check name(s) to final session entry, ensuring uniqueness of input
func (*ManagedSessionEntry) Create ¶
func (b *ManagedSessionEntry) Create(cfg *ManagedSessionConfig) (*ManagedSession, error)
Create returns a new ManagedSession instance based upon this ManagedSessionEntry
func (*ManagedSessionEntry) SetName ¶
func (b *ManagedSessionEntry) SetName(f string, v ...interface{}) *ManagedSessionEntry
SetName sets the name of the to be created session, optionally allowing for replacing
func (*ManagedSessionEntry) SetTTL ¶
func (b *ManagedSessionEntry) SetTTL(ttl time.Duration) *ManagedSessionEntry
SetTTL allows setting of the session TTL from an existing time.Duration instance
type ManagedSessionEntryMutator ¶
type ManagedSessionEntryMutator func(*ManagedSessionEntry)
ManagedSessionEntryMutator defines a callback that may mutate a new MangedSessionBuilder instance
type ManagedSessionState ¶
type ManagedSessionState uint8
const ( // 0x0 - 0xf ManagedSessionStateStopped ManagedSessionState = 0x0 ManagedSessionStateRunning ManagedSessionState = 0x1 ManagedSessionStateShutdowned ManagedSessionState = 0x2 )
func (ManagedSessionState) String ¶
func (s ManagedSessionState) String() string
type ManagedSessionUpdate ¶
type ManagedSessionUpdate struct { ID string `json:"id"` Name string `json:"name"` LastRenewed int64 `json:"last_renewed"` Error error `json:"error"` State ManagedSessionState `json:"state"` }
ManagedSessionUpdate is the value of .Data in all Notification types pushed by a ManagedSession instance
type Notification ¶
type Notification struct { ID string // random Originated int64 // unixnano timestamp of when this notification was created Source NotificationSource Event NotificationEvent Data interface{} // no attempt is made to prevent memory sharing }
Notification describes a specific event with associated data that gets pushed to any registered recipients at the time of push
type NotificationChannel ¶
type NotificationChannel chan Notification
NotificationChannel can be provided to a Notifier to have new Notifications pushed to it
type NotificationEvent ¶
type NotificationEvent uint64
NotificationEvent describes the reason behind a given notification push
const ( NotificationEventManualPush NotificationEvent = 0x0 // sent whenever a manual notification is requested NotificationEventTestPush NotificationEvent = 0xf // used for testing purposes NotificationEventManagedSessionRunning NotificationEvent = 0x80 // sent when session is running NotificationEventManagedSessionStopped NotificationEvent = 0x81 // sent when session is no longer running NotificationEventManagedSessionCreate NotificationEvent = 0x82 // sent after an attempt to create an upstream consul session NotificationEventManagedSessionRenew NotificationEvent = 0x83 // sent after a renew attempt on a previously created upstream consul session NotificationEventManagedSessionDestroy NotificationEvent = 0x84 // sent after a destroy attempt on a previously created upstream consul session NotificationEventManagedSessionShutdowned NotificationEvent = 0x85 // sent after the managed session has been closed and must be considered defunct NotificationEventCandidateRunning NotificationEvent = 0x100 // sent when candidate enters running NotificationEventCandidateStopped NotificationEvent = 0x101 // sent when candidate leaves running NotificationEventCandidateElected NotificationEvent = 0x102 // sent when candidate has been "elected" NotificationEventCandidateLostElection NotificationEvent = 0x103 // sent when candidate lost election NotificationEventCandidateResigned NotificationEvent = 0x104 // sent when candidate explicitly "resigns" NotificationEventCandidateRenew NotificationEvent = 0x105 // sent when candidate was previously elected and attempts to stay elected NotificationEventCandidateShutdowned NotificationEvent = 0x106 // sent when candidate has been closed and must be considered defunct NotificationEventManagedServiceRunning NotificationEvent = 0x180 // sent when the service has reached its "running" state NotificationEventManagedServiceStopped NotificationEvent = 0x181 // sent when the service is considered defunct NotificationEventManagedServiceWatchPlanStarted NotificationEvent = 0x182 // sent when the internal watch plan for the service is running NotificationEventManagedServiceWatchPlanStopped NotificationEvent = 0x183 // sent when the internal watch plan for the service has stopped NotificationEventManagedServiceRefreshed NotificationEvent = 0x184 // sent whenever an attempt is made to refresh the local cache of the service. only successful if Error is nil. NotificationEventManagedServiceMissing NotificationEvent = 0x185 // sent when the upstream service is no longer found NotificationEventManagedServiceTagsAdded NotificationEvent = 0x186 // sent when an add tags attempt is made NotificationEventManagedServiceTagsRemoved NotificationEvent = 0x187 // sent when a remove tags attempt is made NotificationEventManagedServiceShutdowned NotificationEvent = 0x188 // sent when managed service has been closed and must be considered defunct )
func (NotificationEvent) String ¶
func (ev NotificationEvent) String() string
type NotificationHandler ¶
type NotificationHandler func(Notification)
NotificationHandler can be provided to a Notifier to be called per Notification
type NotificationSource ¶
type NotificationSource uint8
NotificationSource identifies the source of the notification push
const ( NotificationSourceManagedSession NotificationSource = iota NotificationSourceCandidate NotificationSourceManagedService NotificationSourceTest NotificationSource = 0xf )
func (NotificationSource) String ¶
func (ns NotificationSource) String() string
type Notifier ¶
type Notifier interface { // AttachNotificationHandler must immediately add the provided fn to the list of recipients for new notifications. // // It must: // - panic if fn is nil // - generate random ID if provided ID is empty // - return "true" if there was an existing recipient with the same identifier AttachNotificationHandler(id string, fn NotificationHandler) (actualID string, replaced bool) // AttachNotificationChannel must immediately add the provided channel to the list of recipients for new // notifications. // // It must: // - panic if ch is nil // - generate random ID if provided ID is empty // - return "true" if there was an existing recipient with the same identifier AttachNotificationChannel(id string, ch NotificationChannel) (actualID string, replaced bool) // DetachNotificationRecipient must immediately remove the provided ID from the list of recipients for new // notifications, if exists. It will return true if a recipient was found with that id. DetachNotificationRecipient(id string) (removed bool) // DetachAllNotificationRecipients must immediately expunge all registered recipients, returning the count of those // detached // // if wait is true, this method will block until all handlers have been closed DetachAllNotificationRecipients(wait bool) int }
Notifier represents a type within Consultant that can push in-process notifications to things.
type NotifierAttachResult ¶
type SimpleServiceRegistration ¶
type SimpleServiceRegistration struct { Name string // [required] name to register service under Port int // [required] external port to advertise for service consumers ID string // [optional] specific id for service, will be generated if not set RandomID bool // [optional] if ID is not set, use a random uuid if true, or hostname if false Address string // [optional] determined automatically by Create() if not set Tags []string // [optional] desired tags: Create() adds serviceId CheckTCP bool // [optional] if true, register a TCP check CheckTTL string // [optional] if defined, registers a ttl check with the value as the starting status CheckPath string // [optional] if defined, register a http check with this path CheckScheme string // [optional] override the http check scheme (default: http) CheckPort int // [optional] tcp or http check port, if defined Interval string // [optional] check renewInterval Timeout time.Duration // [optional] tcp EnableTagOverride bool // [optional] whether we should allow tag overriding (new in 0.6+) }
SimpleServiceRegistration describes a service that we want to register
type SlugParams ¶
SlugParams is used by the ReplaceSlugs helper function
type TagsOption ¶
type TagsOption int
const ( // TagsAll means all tags passed must be present, though other tags are okay TagsAll TagsOption = iota // TagsAny means any service having at least one of the tags are returned TagsAny // TagsExactly means that the service tags must match those passed exactly TagsExactly // TagsExclude means skip services that match any tags passed TagsExclude )
func (TagsOption) String ¶
func (t TagsOption) String() string