cluster

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cluster provides basic tools to build a self-aware cluster of applications. You can join a cluster and query peers that serve general build metadata.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metadata

type Metadata struct {
	Version                string          `json:"version,omitempty"`
	ApplicationName        string          `json:"application_name,omitempty"`
	ApplicationDescription string          `json:"application_description,omitempty"`
	Compiled               time.Time       `json:"compiled,omitempty"`
	Extra                  json.RawMessage `json:"extra,omitempty"`
}

The Metadata type contains fields advertised by nodes in the cluster that describe themselves.

type Node

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

The Node type represents the local node in the cluster.

func JoinLAN

func JoinLAN(opts ...Option) (*Node, error)

JoinLAN attempts to join a LAN-based cluster. It uses the hostname as the node name, and otherwise sets very conservative values that are sane for most LAN environments.

func JoinLocal

func JoinLocal(opts ...Option) (*Node, error)

JoinLocal attempts to join a local cluster. It works similarly to JoinLAN, however it uses a configuration that is optimized for a local loopback environments.

func JoinWAN

func JoinWAN(opts ...Option) (*Node, error)

JoinWAN attempts to join a WAN-based cluster. It uses a configuration that is optimized for most WAN environments.

func (*Node) Close

func (n *Node) Close() error

Close the connection to the cluster.

func (*Node) Peers

func (n *Node) Peers() (peers []*Peer)

Peers returns all currently known Peers in the cluster.

func (*Node) Ping

func (n *Node) Ping() error

Ping returns a non-nil error if the node is not functioning as expected.

type Option

type Option func(cnf *config)

The Option type is a function that modifies the cluster configuration.

func WithExtraMetadata added in v1.5.0

func WithExtraMetadata(extra interface{}) Option

WithExtraMetadata sets an additional metadata value that will be advertised to all nodes in the cluster. The provided interface must allow JSON-encoding. Otherwise, this function will panic.

func WithLogger

func WithLogger(l *log.Logger) Option

WithLogger sets the logger to be used by the discovery mechanism. By default, logging is disabled.

func WithName

func WithName(name string) Option

WithName sets the advertised name of the node, this should be unique across the cluster.

func WithNodes

func WithNodes(nodes []string) Option

WithNodes sets a slice of addresses that the local node will connect to when the cluster is joined.

func WithSecretKey

func WithSecretKey(key string) Option

WithSecretKey sets the secret key to use to encrypt messages between nodes.

type Peer

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

The Peer type represents a peer node in the cluster.

func (*Peer) Address

func (p *Peer) Address() string

Address returns the address of the peer, without a port.

func (*Peer) Metadata

func (p *Peer) Metadata() (*Metadata, error)

Metadata unmarshals the peer's advertised metadata and returns it.

func (*Peer) Name

func (p *Peer) Name() string

Name returns the advertised name of the peer.

Jump to

Keyboard shortcuts

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