embassy

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoServiceMatchesQuery means the query did not find any matches in Consul
	ErrNoServiceMatchesQuery = fmt.Errorf("No services match the query")

	// ErrServicePortNotUnique means there are diferent ports for the same service
	ErrServicePortNotUnique = fmt.Errorf("Service port is not unique!")
)
View Source
var ErrConsulInvalidPath = errors.New("Consul invalid path")

ErrConsulInvalidPath happens when a given KV path is not present

Functions

func GetSRV

func GetSRV(srvName, tag string) (string, int, error)

func GetServiceHost

func GetServiceHost(service, tag string) string

GetServiceHost returns the hostname of a given service

func GetServicePort

func GetServicePort(service, tag string) (int, error)

GetServicePort returns the port associated with a given service

func NewConnection

func NewConnection(settings ConsulSettings) error

Types

type Consul

type Consul struct {
	Service  *Service
	Election *Election
	KV       *MKV
}

Consul - Object used to construct an consul Election and Sevice based on consul tool

func New

func New(settings Settings, log *zap.Logger) (*Consul, error)

New returns an ConsulHandler

type ConsulSettings

type ConsulSettings struct {
	Address  string
	Scheme   string
	Token    string
	CertFile string
	KeyFile  string
	CAFile   string
	Domain   string
}

type Election

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

func NewElection

func NewElection(log *zap.Logger, settings ElectionSettings) (*Election, error)

func (*Election) NewCandidate

func (l *Election) NewCandidate(actions Locker)

func (*Election) StepDown

func (l *Election) StepDown() error

func (*Election) StopWathing

func (l *Election) StopWathing()

func (*Election) WatchMaster

func (l *Election) WatchMaster(action MasterWatcher)

type ElectionSettings

type ElectionSettings struct {
	Key           string
	PoolInterval  string
	ElectionRetry string
}

type KVSettings

type KVSettings struct {
	Path string
}

KVSettings is the configuration for the KV module

type Locker

type Locker interface {
	GotElected(err error)
	LostMaster(err error)
}

type MKV

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

MKV is a wrapper around consul's KV API

func NewKV

func NewKV(log *zap.Logger, settings KVSettings) (*MKV, error)

NewKV returns a MKV object

func (*MKV) Get

func (mkv *MKV) Get(path string) ([]byte, error)

Get retrieves a value from consul

func (*MKV) Put

func (mkv *MKV) Put(path string, value []byte) error

Put adds a value to the KV store

type MasterWatcher

type MasterWatcher interface {
	MasterInfo(name string, found bool, err error)
}

type Semaphore

type Semaphore struct {
	*api.Semaphore
}

Semaphore is an export of Consul's semaphore functionality

func NewResilientSemaphore

func NewResilientSemaphore(name, prefix string, limit, ttl, retries int) (*Semaphore, error)

NewResilientSemaphore constructs a semaphore that doesn't easily dies

func NewSemaphore

func NewSemaphore(name, prefix string, limit int) (*Semaphore, error)

NewSemaphore constructs a semaphore

type Service

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

func NewService

func NewService(log *zap.Logger, settings ServiceSettings) (*Service, error)

func (*Service) AddHTTPcheck

func (srvc *Service) AddHTTPcheck(name, path, interval string) error

func (*Service) AddJobCheck

func (srvc *Service) AddJobCheck(name, interval string) error

func (*Service) AddTTLcheck

func (srvc *Service) AddTTLcheck(name, interval string) error

func (*Service) FailTTL

func (srvc *Service) FailTTL()

func (*Service) GetHealthyOnes

func (srvc *Service) GetHealthyOnes() ([]*api.ServiceEntry, error)

func (*Service) PassTTL

func (srvc *Service) PassTTL()

func (*Service) Register

func (srvc *Service) Register() error

func (*Service) Remove

func (srvc *Service) Remove() error

func (*Service) RemoveCheck

func (srvc *Service) RemoveCheck(checkID string) error

func (*Service) StartKeepAlive

func (srvc *Service) StartKeepAlive(interval string) error

StartKeepAlive uses AddTTLcheck and automatically sends an ping to consul using an goroutine.

func (*Service) StopKeepAlvie

func (srvc *Service) StopKeepAlvie()

func (*Service) StopWathing

func (srvc *Service) StopWathing()

func (*Service) WarnTTL

func (srvc *Service) WarnTTL()

func (*Service) WatchService

func (srvc *Service) WatchService(w ServiceWatcher)

type ServiceSettings

type ServiceSettings struct {
	Name         string
	ID           string
	Tags         []string
	Address      string
	Port         int
	PoolInterval string
}

type ServiceWatcher

type ServiceWatcher interface {
	Health(si *api.ServiceEntry, err error)
	Fail(si *api.ServiceEntry, err error)
}

type Settings

type Settings struct {
	Consul   *ConsulSettings   `json:"consul"`
	Election *ElectionSettings `json:"election"`
	Service  *ServiceSettings  `json:"service"`
	KV       *KVSettings       `json:"kv"`
}

Settings aggregates Service and Election settings

Jump to

Keyboard shortcuts

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