Documentation ¶
Index ¶
- Constants
- Variables
- func Deregister(ctx context.Context, connection *consul.Connection, ...) error
- func NewRegistration(opts ...RegistrationOptions) *api.AgentServiceRegistration
- func Register(ctx context.Context, connection *consul.Connection, ...) error
- type Callback
- type Client
- type ClientConfig
- type ClientOptions
- type ConsulInstancer
- func (i *ConsulInstancer) Deregister(ch chan<- sd.Event)
- func (i *ConsulInstancer) DeregisterCallback(id interface{})
- func (i *ConsulInstancer) Instances(matcher InstanceMatcher) (ret []*Instance, err error)
- func (i *ConsulInstancer) Register(ch chan<- sd.Event)
- func (i *ConsulInstancer) RegisterCallback(id interface{}, cb Callback)
- func (i *ConsulInstancer) Service() (svc *Service)
- func (i *ConsulInstancer) ServiceName() string
- func (i *ConsulInstancer) Start(ctx context.Context)
- func (i *ConsulInstancer) Stop()
- type ConsulInstancerOption
- type ConsulInstancerOptions
- type Customizer
- type CustomizerFunc
- type Customizers
- type DefaultCustomizer
- type DiscoveryProperties
- type HealthStatus
- type Instance
- type InstanceMatcher
- func InstanceIsHealthy() InstanceMatcher
- func InstanceWithHealth(status HealthStatus) InstanceMatcher
- func InstanceWithMetaKV(key, value string) InstanceMatcher
- func InstanceWithProperties(props *SelectorProperties) InstanceMatcher
- func InstanceWithTag(tag string, caseInsensitive bool) InstanceMatcher
- func InstanceWithTagKV(key, value string, caseInsensitive bool) InstanceMatcher
- func InstanceWithVersion(verPattern string) InstanceMatcher
- type Instancer
- type RegistrationConfig
- type RegistrationOptions
- type SelectorProperties
- type Service
- type ServiceCache
Constants ¶
const ( TAG_INSTANCE_ID = "instanceUuid" TAG_MANAGED_SERVICE = "managedMicroservice" TAG_COMPONENT_ATTRIBUTES = "componentAttributes" TAG_SERVICE_NAME = "name" TAG_VERSION = "version" TAG_BUILD_NUMBER = "buildNumber" TAG_BUILD_DATE_TIME = "buildDateTime" COMPONENT_ATTRIBUTE_DELIMITER = "~" KEY_VALUE_SEPARATOR = ":" )
const ( InstanceMetaKeyVersion = "version" InstanceMetaKeyContextPath = "context" InstanceMetaKeySMCR = "SMCR" InstanceMetaKeySecure = "secure" )
const (
DiscoveryPropertiesPrefix = "cloud.consul.discovery"
)
Variables ¶
var COMPONENT_ATTRIBUTES_MAPPING = map[string]string{
"serviceName": "application.name",
"context": "server.context-path",
"name": "info.app.attributes.displayName",
"description": "info.app.description",
"parent": "info.app.attributes.parent",
"type": "info.app.attributes.type",
}
var (
ErrInstancerStopped = fmt.Errorf("instancer is already stopped")
)
Functions ¶
func Deregister ¶
func Deregister(ctx context.Context, connection *consul.Connection, registration *api.AgentServiceRegistration) error
func NewRegistration ¶
func NewRegistration(opts ...RegistrationOptions) *api.AgentServiceRegistration
func Register ¶
func Register(ctx context.Context, connection *consul.Connection, registration *api.AgentServiceRegistration) error
Types ¶
type Client ¶
type Client interface { Context() context.Context Instancer(serviceName string) (Instancer, error) }
func NewConsulDiscoveryClient ¶
func NewConsulDiscoveryClient(ctx context.Context, conn *consul.Connection, opts ...ClientOptions) Client
type ClientConfig ¶
type ClientConfig struct { Logger log.Logger Verbose bool DefaultSelector InstanceMatcher }
type ClientOptions ¶
type ClientOptions func(opt *ClientConfig)
type ConsulInstancer ¶
type ConsulInstancer struct {
// contains filtered or unexported fields
}
ConsulInstancer implements sd.Instancer and Instancer. It yields service for a serviceName in Consul. Note: implementing sd.Instancer is for compatibility reason, using it involves addtional Lock locking.
Try use Instancer's callback capability instead
func NewConsulInstancer ¶
func NewConsulInstancer(ctx context.Context, opts ...ConsulInstancerOptions) *ConsulInstancer
NewConsulInstancer returns a customized Consul instancer that publishes service for the requested serviceName. It only returns service for which the passed tags are present.
func (*ConsulInstancer) Deregister ¶
func (i *ConsulInstancer) Deregister(ch chan<- sd.Event)
Deregister implements sd.Instancer.
func (*ConsulInstancer) DeregisterCallback ¶
func (i *ConsulInstancer) DeregisterCallback(id interface{})
func (*ConsulInstancer) Instances ¶
func (i *ConsulInstancer) Instances(matcher InstanceMatcher) (ret []*Instance, err error)
Instances implements Instancer
func (*ConsulInstancer) Register ¶
func (i *ConsulInstancer) Register(ch chan<- sd.Event)
Register implements sd.Instancer.
func (*ConsulInstancer) RegisterCallback ¶
func (i *ConsulInstancer) RegisterCallback(id interface{}, cb Callback)
func (*ConsulInstancer) Service ¶
func (i *ConsulInstancer) Service() (svc *Service)
Service implements Instancer
func (*ConsulInstancer) ServiceName ¶
func (i *ConsulInstancer) ServiceName() string
ServiceName implements Instancer
func (*ConsulInstancer) Start ¶
func (i *ConsulInstancer) Start(ctx context.Context)
func (*ConsulInstancer) Stop ¶
func (i *ConsulInstancer) Stop()
Stop implements sd.Instancer and Instancer.
type ConsulInstancerOption ¶
type ConsulInstancerOption struct { ServiceName string ConsulConnection *consul.Connection Logger log.Logger Selector InstanceMatcher Verbose bool }
type ConsulInstancerOptions ¶
type ConsulInstancerOptions func(opt *ConsulInstancerOption)
type Customizer ¶
type Customizer interface {
Customize(ctx context.Context, reg *api.AgentServiceRegistration)
}
type CustomizerFunc ¶
type CustomizerFunc func(ctx context.Context, reg *api.AgentServiceRegistration)
func (CustomizerFunc) Customize ¶
func (fn CustomizerFunc) Customize(ctx context.Context, reg *api.AgentServiceRegistration)
type Customizers ¶
type Customizers struct { Customizers []Customizer // contains filtered or unexported fields }
func NewCustomizers ¶
func NewCustomizers(ctx *bootstrap.ApplicationContext) *Customizers
func (*Customizers) Add ¶
func (r *Customizers) Add(c Customizer)
func (*Customizers) Apply ¶
func (r *Customizers) Apply(ctx context.Context, registration *api.AgentServiceRegistration)
type DefaultCustomizer ¶
type DefaultCustomizer struct {
// contains filtered or unexported fields
}
func NewDefaultCustomizer ¶
func NewDefaultCustomizer(appContext *bootstrap.ApplicationContext) *DefaultCustomizer
func (*DefaultCustomizer) Customize ¶
func (d *DefaultCustomizer) Customize(ctx context.Context, registration *api.AgentServiceRegistration)
type DiscoveryProperties ¶
type DiscoveryProperties struct { HealthCheckPath string `json:"health-check-path"` HealthCheckInterval string `json:"health-check-interval"` Tags utils.CommaSeparatedSlice `json:"tags"` AclToken string `json:"acl-token"` IpAddress string `json:"ip-address"` //A pre-defined IP address Interface string `json:"interface"` //The network interface from where to get the ip address. If IpAddress is defined, this field is ignored Port int `json:"port"` Scheme string `json:"scheme"` HealthCheckCriticalTimeout string `json:"health-check-critical-timeout"` //See api.AgentServiceCheck's DeregisterCriticalServiceAfter field DefaultSelector SelectorProperties `json:"default-selector"` // Default tags or meta to use when discovering other services }
func BindDiscoveryProperties ¶
func BindDiscoveryProperties(ctx *bootstrap.ApplicationContext) DiscoveryProperties
func NewDiscoveryProperties ¶
func NewDiscoveryProperties() *DiscoveryProperties
type HealthStatus ¶
type HealthStatus int
HealthStatus maintenance > critical > warning > passing
const ( HealthAny HealthStatus = iota HealthPassing HealthWarning HealthCritical HealthMaintenance )
type InstanceMatcher ¶
type InstanceMatcher matcher.ChainableMatcher
InstanceMatcher is a matcher.Matcher that takes Instance or *Instance
func InstanceIsHealthy ¶
func InstanceIsHealthy() InstanceMatcher
InstanceIsHealthy returns an InstanceMatcher that matches healthy instances
func InstanceWithHealth ¶
func InstanceWithHealth(status HealthStatus) InstanceMatcher
func InstanceWithMetaKV ¶
func InstanceWithMetaKV(key, value string) InstanceMatcher
func InstanceWithProperties ¶
func InstanceWithProperties(props *SelectorProperties) InstanceMatcher
InstanceWithProperties returns an InstanceMatcher that matches instances described in given selector properties could return nil
func InstanceWithTag ¶
func InstanceWithTag(tag string, caseInsensitive bool) InstanceMatcher
func InstanceWithTagKV ¶
func InstanceWithTagKV(key, value string, caseInsensitive bool) InstanceMatcher
func InstanceWithVersion ¶
func InstanceWithVersion(verPattern string) InstanceMatcher
type RegistrationConfig ¶
type RegistrationOptions ¶
type RegistrationOptions func(cfg *RegistrationConfig)
func RegistrationWithProperties ¶
func RegistrationWithProperties(appCtx *bootstrap.ApplicationContext, props DiscoveryProperties) RegistrationOptions
type SelectorProperties ¶
type SelectorProperties struct { Tags utils.CommaSeparatedSlice `json:"tags"` Meta map[string]string `json:"meta"` }
type Service ¶
func (*Service) InstanceCount ¶
func (s *Service) InstanceCount(selector InstanceMatcher) (ret int)
func (*Service) Instances ¶
func (s *Service) Instances(selector InstanceMatcher) (ret []*Instance)
type ServiceCache ¶
type ServiceCache interface { // Get returns service with given service name. return nil if not exist Get(name string) *Service // Set stores given service with name, returns non-nil if the service is already exists Set(name string, svc *Service) *Service // SetWithTTL stores given service with name and TTL, returns non-nil if the service is already exists // if ttl is zero or negative value, it's equivalent to Set SetWithTTL(name string, svc *Service, ttl time.Duration) *Service Has(name string) bool Entries() map[string]*Service }
ServiceCache is not goroutine-safe unless the detail implementation says so