{"modulePath":"github.com/vcabbage/kit","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package sd\n\nPackage sd provides utilities related to service discovery. That includes the client-side loadbalancer pattern, where a microservice subscribes to a service discovery system in order to reach remote instances; as well as the registrator pattern, where a microservice registers itself in a service discovery system. Implementations are provided for most common systems.\n\n## Types\n\n```go\ntype DefaultEndpointer struct {\n\t// contains filtered or unexported fields\n}\n```\nDefaultEndpointer implements an Endpointer interface. When created with NewEndpointer function, it automatically registers as a subscriber to events from the Instances and maintains a list of active Endpoints.\n\n```go\nfunc NewEndpointer(src Instancer, f Factory, logger log.Logger, options ...EndpointerOption) *DefaultEndpointer\n```\nNewEndpointer creates an Endpointer that subscribes to updates from Instancer src and uses factory f to create Endpoints. If src notifies of an error, the Endpointer keeps returning previously created Endpoints assuming they are still good, unless this behavior is disabled via InvalidateOnError option.\n\n```go\nfunc (de *DefaultEndpointer) Close()\n```\nClose de-registeres DefaultEndpointer from the Instancer and stops the internal go-routine.\n\n```go\nfunc (de *DefaultEndpointer) Endpoints() ([]endpoint.Endpoint, error)\n```\nEndpoints implements Endpointer.\n\n```go\ntype Endpointer interface {\n\tEndpoints() ([]endpoint.Endpoint, error)\n}\n```\nEndpointer listens to a service discovery system and yields a set of identical endpoints on demand. An error indicates a problem with connectivity to the service discovery system, or within the system itself; an Endpointer may yield no endpoints without error.\n\n```go\ntype EndpointerOption func(*endpointerOptions)\n```\nEndpointerOption allows control of endpointCache behavior.\n\n```go\nfunc InvalidateOnError(timeout time.Duration) EndpointerOption\n```\nInvalidateOnError returns EndpointerOption that controls how the Endpointer behaves when then Instancer publishes an Event containing an error. Without this option the Endpointer continues returning the last known endpoints. With this option, the Endpointer continues returning the last known endpoints until the timeout elapses, then closes all active endpoints and starts returning an error. Once the Instancer sends a new update with valid resource instances, the normal operation is resumed.\n\n```go\ntype Event struct {\n\tInstances []string\n\tErr       error\n}\n```\nEvent represents a push notification generated from the underlying service discovery implementation. It contains either a full set of available resource instances, or an error indicating some issue with obtaining information from discovery backend. Examples of errors may include loosing connection to the discovery backend, or trying to look up resource instances using an incorrectly formatted key. After receiving an Event with an error the listenter should treat previously discovered resource instances as stale (although it may choose to continue using them). If the Instancer is able to restore connection to the discovery backend it must push another Event with the current set of resource instances.\n\n```go\ntype Factory func(instance string) (endpoint.Endpoint, io.Closer, error)\n```\nFactory is a function that converts an instance string (e.g. host:port) to a specific endpoint. Instances that provide multiple endpoints require multiple factories. A factory also returns an io.Closer that's invoked when the instance goes away and needs to be cleaned up. Factories may return nil closers.\n\nUsers are expected to provide their own factory functions that assume specific transports, or can deduce transports by parsing the instance string.\n\n```go\ntype FixedEndpointer []endpoint.Endpoint\n```\nFixedEndpointer yields a fixed set of endpoints.\n\n```go\nfunc (s FixedEndpointer) Endpoints() ([]endpoint.Endpoint, error)\n```\nEndpoints implements Endpointer.\n\n```go\ntype FixedInstancer []string\n```\nFixedInstancer yields a fixed set of instances.\n\n```go\nfunc (d FixedInstancer) Deregister(ch chan\u003c- Event)\n```\nDeregister implements Instancer.\n\n```go\nfunc (d FixedInstancer) Register(ch chan\u003c- Event)\n```\nRegister implements Instancer.\n\n```go\ntype Instancer interface {\n\tRegister(chan\u003c- Event)\n\tDeregister(chan\u003c- Event)\n}\n```\nInstancer listens to a service discovery system and notifies registered observers of changes in the resource instances. Every event sent to the channels contains a complete set of instances known to the Instancer. That complete set is sent immediately upon registering the channel, and on any future updates from discovery system.\n\n```go\ntype Registrar interface {\n\tRegister()\n\tDeregister()\n}\n```\nRegistrar registers instance information to a service discovery system when an instance becomes alive and healthy, and deregisters that information when the service becomes unhealthy or goes away.\n\nRegistrar implementations exist for various service discovery systems. Note that identifying instance information (e.g. host:port) must be given via the concrete constructor; this interface merely signals lifecycle changes.\n\n","path":"github.com/vcabbage/kit/sd","name":"sd","synopsis":"Package sd provides utilities related to service discovery.","isRedistributable":true}
