etcd

package module
v0.0.0-...-ed0ca78 Latest Latest
Warning

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

Go to latest
Published: May 28, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

Krakend ETCD

An etcd client and subscriber for the KrakenD framework.

Build the example

Go 1.8 is a requirement

$ make

Run

Running it as a common executable, logs are send to the stdOut and some options are available at the CLI

$ ./krakend_etcd_example
Usage of ./krakend_etcd_example:
  -c string
    	Path to the configuration filename (default "/etc/krakend/configuration.json")
  -d	Enable the debug
  -etcd string
    	Comma-separated list of etcd servers (with port and schema) (default "http://192.168.99.100:4001")
  -l string
    	Logging level (default "ERROR")
  -p int
    	Port of the service

Documentation

Index

Constants

View Source
const Namespace = "github_com/devopsfaith/krakend-etcd"

Namespace is the key to use to store and access the custom config data

Variables

View Source
var (
	// ErrNoConfig is the error to be returned when there is no config with the etcd namespace
	ErrNoConfig = fmt.Errorf("unable to create the etcd client: no config")
	// ErrBadConfig is the error to be returned when the config is not well defined
	ErrBadConfig = fmt.Errorf("unable to create the etcd client with the received config")
	// ErrNoMachines is the error to be returned when the config has not defined one or more servers
	ErrNoMachines = fmt.Errorf("unable to create the etcd client without a set of servers")
	// ErrNilClient is the error to be nil client
	ErrNilClient = fmt.Errorf("nil etcd client")
)

Functions

func SubscriberFactory

func SubscriberFactory(ctx context.Context, c Client) sd.SubscriberFactory

SubscriberFactory builds a an etcd subscriber SubscriberFactory with the received etcd client

Types

type Client

type Client interface {
	// GetEntries queries the given prefix in etcd and returns a slice
	// containing the values of all keys found, recursively, underneath that
	// prefix.
	GetEntries(prefix string) ([]string, error)

	// WatchPrefix watches the given prefix in etcd for changes. When a change
	// is detected, it will signal on the passed channel. Clients are expected
	// to call GetEntries to update themselves with the latest set of complete
	// values. WatchPrefix will always send an initial sentinel value on the
	// channel after establishing the watch, to ensure that clients always
	// receive the latest set of values. WatchPrefix will block until the
	// context passed to the NewClient constructor is terminated.
	WatchPrefix(prefix string, ch chan struct{})
}

Client is a wrapper around the etcd client.

func New

New creates an etcd client with the config extracted from the extra config param

func NewClient

func NewClient(ctx context.Context, machines []string, options ClientOptions) (Client, error)

NewClient returns Client with a connection to the named machines. It will return an error if a connection to the cluster cannot be made. The parameter machines needs to be a full URL with schemas. e.g. "http://localhost:2379" will work, but "localhost:2379" will not.

func NewClientV3

func NewClientV3(ctx context.Context, machines []string, options ClientOptions) (Client, error)

NewClient returns Client with a connection to the named machines. It will return an error if a connection to the cluster cannot be made. The parameter machines needs to be a full URL with schemas. e.g. "http://localhost:2379" will work, but "localhost:2379" will not.

type ClientOptions

type ClientOptions struct {
	Cert                    string
	Key                     string
	CACert                  string
	DialTimeout             time.Duration
	DialKeepAlive           time.Duration
	DialKeepAliveTimeout    time.Duration
	HeaderTimeoutPerRequest time.Duration
}

ClientOptions defines options for the etcd client. All values are optional. If any duration is not specified, a default of 3 seconds will be used.

type Subscriber

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

Subscriber keeps instances stored in a certain etcd keyspace cached in a fixed subscriber. Any kind of change in that keyspace is watched and will update the Subscriber's list of hosts.

func NewSubscriber

func NewSubscriber(ctx context.Context, c Client, prefix string) (*Subscriber, error)

NewSubscriber returns an etcd subscriber. It will start watching the given prefix for changes, and update the subscribers.

func (Subscriber) Hosts

func (s Subscriber) Hosts() ([]string, error)

Hosts implements the subscriber interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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