discov

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TimeToLive = timeToLive

TimeToLive is seconds to live in etcd.

Functions

func EncodePublishInfo

func EncodePublishInfo(info *PublishInfo) (string, error)

func RegisterAccount

func RegisterAccount(endpoints []string, user, pass string)

RegisterAccount registers the username/password to the given etcd cluster.

func RegisterTLS

func RegisterTLS(endpoints []string, certFile, certKeyFile, caFile string,
	insecureSkipVerify bool) error

RegisterTLS registers the CertFile/CertKeyFile/CACertFile to the given etcd.

Types

type Container

type Container interface {
	OnAdd(kv internal.KV)
	OnDelete(kv internal.KV)
	AddListener(listener func())
	GetValues() []string
}

type EtcdConf

type EtcdConf struct {
	Hosts              []string
	Key                string
	ID                 int64  `json:",optional"`
	InstanceID         string `json:",optional"`
	User               string `json:",optional"`
	Pass               string `json:",optional"`
	CertFile           string `json:",optional"`
	CertKeyFile        string `json:",optional=CertFile"`
	CACertFile         string `json:",optional=CertFile"`
	InsecureSkipVerify bool   `json:",optional"`
}

EtcdConf is the config item with the given key on etcd.

func (EtcdConf) HasAccount

func (c EtcdConf) HasAccount() bool

HasAccount returns if account provided.

func (EtcdConf) HasID

func (c EtcdConf) HasID() bool

HasID returns if ID provided.

func (EtcdConf) HasTLS

func (c EtcdConf) HasTLS() bool

HasTLS returns if TLS CertFile/CertKeyFile/CACertFile are provided.

func (EtcdConf) Validate

func (c EtcdConf) Validate() error

Validate validates c.

type InstanceState added in v0.3.0

type InstanceState string

InstanceState describes whether a discovered instance accepts ordinary traffic.

const (
	InstanceReady    InstanceState = "ready"
	InstanceDraining InstanceState = "draining"
)

func (InstanceState) Valid added in v0.3.0

func (s InstanceState) Valid() bool

type KV

type KV = internal.KV

type PubOption

type PubOption func(client *Publisher)

PubOption defines the method to customize a Publisher.

func WithId

func WithId(id int64) PubOption

WithId customizes a Publisher with the id.

func WithPubEtcdAccount

func WithPubEtcdAccount(user, pass string) PubOption

WithPubEtcdAccount provides the etcd username/password.

func WithPubEtcdTLS

func WithPubEtcdTLS(certFile, certKeyFile, caFile string, insecureSkipVerify bool) PubOption

WithPubEtcdTLS provides the etcd CertFile/CertKeyFile/CACertFile.

type PublishInfo

type PublishInfo struct {
	Addr       string
	InstanceID string
	State      InstanceState
}

func DecodePublishInfo

func DecodePublishInfo(data string) (*PublishInfo, error)

type Publisher

type Publisher struct {
	// contains filtered or unexported fields
}

A Publisher can be used to publish the value to an etcd cluster on the given key.

func NewPublisher

func NewPublisher(endpoints []string, key, value string, opts ...PubOption) *Publisher

NewPublisher returns a Publisher. endpoints is the hosts of the etcd cluster. key:value are a pair to be published. opts are used to customize the Publisher.

func (*Publisher) Close added in v0.3.0

func (p *Publisher) Close() error

Close stops renewing and synchronously revokes the active registration.

func (*Publisher) KeepAlive

func (p *Publisher) KeepAlive() error

KeepAlive keeps key:value alive.

func (*Publisher) Pause

func (p *Publisher) Pause()

Pause pauses the renewing of key:value.

func (*Publisher) Resume

func (p *Publisher) Resume()

Resume resumes the renewing of key:value.

func (*Publisher) Stop

func (p *Publisher) Stop()

Stop stops the renewing and revokes the registration.

func (*Publisher) Update added in v0.3.0

func (p *Publisher) Update(value string) error

Update atomically changes the value attached to the current lease.

type SubOption

type SubOption func(sub *Subscriber)

SubOption defines the method to customize a Subscriber.

func Exclusive

func Exclusive() SubOption

Exclusive means that key value can only be 1:1, which means later added value will remove the keys associated with the same value previously.

func WithContainer

func WithContainer(container Container) SubOption

WithContainer provides a custom container to the subscriber.

func WithExactMatch

func WithExactMatch() SubOption

WithExactMatch turn off querying using key prefixes.

func WithSubEtcdAccount

func WithSubEtcdAccount(user, pass string) SubOption

WithSubEtcdAccount provides the etcd username/password.

func WithSubEtcdTLS

func WithSubEtcdTLS(certFile, certKeyFile, caFile string, insecureSkipVerify bool) SubOption

WithSubEtcdTLS provides the etcd CertFile/CertKeyFile/CACertFile.

type Subscriber

type Subscriber struct {
	// contains filtered or unexported fields
}

A Subscriber is used to subscribe the given key on an etcd cluster.

func NewSubscriber

func NewSubscriber(endpoints []string, key string, opts ...SubOption) (*Subscriber, error)

NewSubscriber returns a Subscriber. endpoints is the hosts of the etcd cluster. key is the key to subscribe. opts are used to customize the Subscriber.

func (*Subscriber) AddListener

func (s *Subscriber) AddListener(listener func())

AddListener adds listener to s.

func (*Subscriber) Close

func (s *Subscriber) Close()

Close closes the subscriber.

func (*Subscriber) Instances added in v0.3.0

func (s *Subscriber) Instances() []PublishInfo

Instances returns the valid service instances in the current snapshot. Malformed entries are isolated so that one bad registration cannot hide healthy instances published under the same discovery key.

func (*Subscriber) Values

func (s *Subscriber) Values() []string

Values returns all the subscription values.

Directories

Path Synopsis
Package internal is a generated GoMock package.
Package internal is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL