consul

package
v0.0.0-...-118e354 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicAuthConfig

type BasicAuthConfig struct {
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
}

BasicAuthConfig stores HTTP Basic Auth credentials.

type Client

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

Client represents a Consul client.

func New

func New(key string, cfg *Config) (*Client, error)

New returns an instantiated Consul client. If the cfg is nil, the default config is used.

func (*Client) Close

func (c *Client) Close() error

Close closes the client.

func (*Client) GetLeader

func (c *Client) GetLeader() (id string, apiAddr string, addr string, ok bool, e error)

GetLeader returns the leader as recorded in Consul. If a leader exists, ok will be set to true, false otherwise.

func (*Client) InitializeLeader

func (c *Client) InitializeLeader(id, apiAddr, addr string) (bool, error)

InitializeLeader sets the leader to the given details, but only if no leader has already been set. This operation is a check-and-set type operation. If initialization succeeds, ok is set to true.

func (*Client) SetLeader

func (c *Client) SetLeader(id, apiAddr, addr string) error

SetLeader unconditionally sets the leader to the given details.

func (*Client) String

func (c *Client) String() string

String implements the Stringer interface.

type Config

type Config struct {
	// Address is the address of the Consul server
	Address string `json:"address,omitempty"`

	// Scheme is the URI scheme for the Consul server
	Scheme string `json:"scheme,omitempty"`

	// Datacenter to use. If not provided, the default agent datacenter is used.
	Datacenter string `json:"datacenter,omitempty"`

	// BasicAuth sets the HTTP BasicAuth credentials for talking to Consul
	BasicAuth *BasicAuthConfig `json:"basic_auth,omitempty"`

	// Token is used to provide a per-request ACL token
	// which overrides the agent's default token.
	Token string `json:"token,omitempty"`

	// TokenFile is a file containing the current token to use for this client.
	// If provided it is read once at startup and never again.
	TokenFile string `json:"token_file,omitempty"`

	// Namespace is the name of the namespace to send along for the request
	// when no other Namespace is present in the QueryOptions
	Namespace string `json:"namespace,omitempty"`

	// Partition is the name of the partition to send along for the request
	// when no other Partition is present in the QueryOptions
	Partition string `json:"partition,omitempty"`

	// TLSConfig is the TLS config for talking to Consul
	TLSConfig *TLSConfig `json:"tls_config,omitempty"`
}

Config for Consul client.

func NewConfigFromFile

func NewConfigFromFile(path string) (*Config, error)

NewConfigFromFile parses the file at path and returns a Config.

func NewConfigFromReader

func NewConfigFromReader(r io.Reader) (*Config, error)

NewConfigFromReader parses the data returned by the reader and returns a Config. A nil reader results in nil config.

type TLSConfig

type TLSConfig struct {
	// Address is the optional address of the Consul server. The port, if any
	// will be removed from here and this will be set to the ServerName of the
	// resulting config.
	Address string `json:"address,omitempty"`

	// CAFile is the optional path to the CA certificate used for Consul
	// communication, defaults to the system bundle if not specified.
	CAFile string `json:"ca_file,omitempty"`

	// CAPath is the optional path to a directory of CA certificates to use for
	// Consul communication, defaults to the system bundle if not specified.
	CAPath string `json:"ca_path,omitempty"`

	// CAPem is the optional PEM-encoded CA certificate used for Consul
	// communication, defaults to the system bundle if not specified.
	CAPem []byte `json:"ca_pem,omitempty"`

	// CertFile is the optional path to the certificate for Consul
	// communication. If this is set then you need to also set KeyFile.
	CertFile string `json:"cert_file,omitempty"`

	// CertPEM is the optional PEM-encoded certificate for Consul
	// communication. If this is set then you need to also set KeyPEM.
	CertPEM []byte `json:"cert_pem,omitempty"`

	// KeyFile is the optional path to the private key for Consul communication.
	// If this is set then you need to also set CertFile.
	KeyFile string `json:"key_file,omitempty"`

	// KeyPEM is the optional PEM-encoded private key for Consul communication.
	// If this is set then you need to also set CertPEM.
	KeyPEM []byte `json:"key_pem,omitempty"`

	// InsecureSkipVerify if set to true will disable TLS host verification.
	InsecureSkipVerify bool `json:"insecure_skip_verify,omitempty"`
}

TLSConfig sets the configuration for TLS communication with Consul.

Jump to

Keyboard shortcuts

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