Documentation
¶
Index ¶
- Constants
- func AddRuntimeLabel(label Label) error
- func Compare(discoveryA, discoveryB Discovery) bool
- func RemoveRuntimeLabel(label Label) error
- type Discoveries
- func (d *Discoveries) Add(discovery Discovery)
- func (d *Discoveries) Clean()
- func (d *Discoveries) Delete(hostname string)
- func (d *Discoveries) Exist(hostname string) bool
- func (d *Discoveries) Filter(labelsFilter []string) []Discovery
- func (d *Discoveries) FilterPrefix(prefixes []string) []Discovery
- func (d *Discoveries) Get(hostname string) Discovery
- func (d *Discoveries) GetAll() []Discovery
- func (d *Discoveries) Refresh(hostname string)
- type Discovery
- type Label
- type Labels
- type LocalHost
Constants ¶
const TimeToLife = 60 // when server won't occur in the discovery channel longer than this, it should be considered as not-alive
Variables ¶
This section is empty.
Functions ¶
func AddRuntimeLabel ¶
func RemoveRuntimeLabel ¶
Types ¶
type Discoveries ¶
type Discoveries struct {
LogChannel chan string
TTL uint
// contains filtered or unexported fields
}
Discoveries helps to store instances of Discovery struct and access them in thread safe mode
func (*Discoveries) Add ¶
func (d *Discoveries) Add(discovery Discovery)
Add appends a new discovery/server to the storage
func (*Discoveries) Clean ¶
func (d *Discoveries) Clean()
Clean checks loops over last check values for each discovery object and removes it if it's passed
func (*Discoveries) Delete ¶
func (d *Discoveries) Delete(hostname string)
Delete removes server identified by hostname from the storage
func (*Discoveries) Exist ¶
func (d *Discoveries) Exist(hostname string) bool
Exist returns true if server with given hostname exists
func (*Discoveries) Filter ¶
func (d *Discoveries) Filter(labelsFilter []string) []Discovery
Filter returns list of discoveries based on given labels
func (*Discoveries) FilterPrefix ¶
func (d *Discoveries) FilterPrefix(prefixes []string) []Discovery
Filter returns list of discoveries based on given label prefixes.
func (*Discoveries) Get ¶
func (d *Discoveries) Get(hostname string) Discovery
Get returns Discovery struct with the given hostname but it can be also an empty struct if it's not found. Check if hostname is empty or use Exist first to be sure.
func (*Discoveries) GetAll ¶
func (d *Discoveries) GetAll() []Discovery
GetAll returns copy of the internal storage
type Discovery ¶
type Discovery struct {
Hostname string `json:"hostname"`
Labels Labels `json:"labels"`
// For internal use to check if the server is still alive.
// Contains timestamp of the last check.
LastCheck int64 `json:"last_check"`
TTL uint `json:"-"` // after how many second consider the server to be off, if 0 then 60 secs is used
}
Discovery contains information about a single server and is used for server discovery
func (*Discovery) FindLabelsByPrefix ¶
FindLabelsByPrefix returns list of labels with given prefix. For example "service:ns" has prefix "service" or "service:". It doesn't have to be prefix, but for example "service:test" will match "service:test" and also "service:test2".
func (*Discovery) SortLabels ¶
func (d *Discovery) SortLabels()
type Label ¶
type Label string
Label keeps one piece of information about a single server
func (Label) GetPart ¶
GetPart returns specific part of the label, if part index is higher than last available index it returns empty string.
type Labels ¶
type Labels []Label
Labels stores multiple Label records
func (*Labels) StringSlice ¶
StringSlice return slice of Label as strings
type LocalHost ¶
type LocalHost struct {
LabelsPath string // Where labels are stored
RuntimeLabelsFilename string // Filename under which are runtime labels saved in LabelsPath
InitialLabels Labels // this usually coming from the config
HostnameOverride string // if not empty string hostname in the discovery packet will be replaced by this
}
func (*LocalHost) DeleteLabels ¶
DeleteLabels removed labels from LabelsPath directory. Only labels added this way can be deleted.
func (*LocalHost) GetIdentification ¶
GetIdentification assembles the discovery packet that contains hotname and set of labels describing a single server, in this case the local server. Parameter initialLabels usually coming from configuration of the app. If hostname is empty it will be discovered automatically.