cluster

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigEnvPaths = [][]string{}/* 123 elements not displayed */

Functions

func HasInstance

func HasInstance(cluster ClusterConfig, name string) bool

HasInstance returns true if an instance with the name exists in the config.

func Instances

func Instances(cluster ClusterConfig) []string

Instances returns a list of instance names from the cluster config.

Types

type ClusterConfig

type ClusterConfig struct {
	// RawConfig is a configuration of the global scope.
	RawConfig *Config `yaml:"-"`
	// Groups are parsed configurations per a group.
	Groups map[string]GroupConfig
}

ClusterConfig describes a cluster configuration.

func GetClusterConfig

func GetClusterConfig(path string) (ClusterConfig, error)

GetClusterConfig returns a cluster configuration loaded from a path to a config file. It uses a a config file, etcd and default environment variables as sources. The function returns a cluster config as is, without merging of settings from scopes: global, group, replicaset, instance.

func MakeClusterConfig

func MakeClusterConfig(config *Config) (ClusterConfig, error)

MakeClusterConfig creates a ClusterConfig object from a configuration.

func (*ClusterConfig) UnmarshalYAML

func (c *ClusterConfig) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML helps to unmarshal a ClusterConfig object from YAML.

type Collector

type Collector interface {
	// Collect collects a configuration or returns an error.
	Collect() (*Config, error)
}

Collector interface must be implemented by a configuration source collector.

type Config

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

Config is a container for deserialized configuration.

func Instantiate

func Instantiate(cluster ClusterConfig, name string) *Config

Instantiate returns a fetched instance config from the cluster config. If the cluster config has the instance then it returns a merged config of the instance from scopes: global, group, replicaset, instance. If the cluster config has not the instance then it returns a global scope of the cluster config.

func NewConfig

func NewConfig() *Config

NewConfig creates a new empty configuration.

func (*Config) Elems

func (c *Config) Elems(path []string) ([]string, error)

Elems returns a list of an elements for a path.

func (*Config) ForEach

func (c *Config) ForEach(path []string, fun func(path []string, value any))

ForEach iterates over each value in the configuration.

func (*Config) Get

func (c *Config) Get(path []string) (any, error)

Get returns a value from a configuration path.

func (*Config) Merge

func (c *Config) Merge(low *Config)

Merge merges a configuration to the current. The outside configuration has a low priority.

func (*Config) Set

func (c *Config) Set(path []string, value any) error

Set sets a value to a configuration path.

func (*Config) String

func (c *Config) String() string

String returns a string representation of the configuration. Actually it is a valid YAML.

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML helps to unmarshal the configuration from a YAML document.

type EnvCollector

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

EnvCollector collects a configuration from environment variables.

func NewEnvCollector

func NewEnvCollector(formatter func(path []string) string) EnvCollector

NewEnvCollector creates a new EnvCollector. A path to an environment variable format function must be specified.

func (EnvCollector) Collect

func (c EnvCollector) Collect() (*Config, error)

Collect collects a configuration from environment variables.

type FileCollector

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

FileCollector collects data from a YAML file.

func NewFileCollector

func NewFileCollector(path string) FileCollector

NewFileCollector create a new file collector for a path.

func (FileCollector) Collect

func (c FileCollector) Collect() (*Config, error)

Collect collects a configuration from a file located at a specified path.

type GroupConfig

type GroupConfig struct {
	// RawConfig is a raw configuration of the group scope.
	RawConfig *Config `yaml:"-"`
	// Replicasets are parsed configurations per a replicaset.
	Replicasets map[string]ReplicasetConfig
}

GroupConfig describes a group configuration.

func (*GroupConfig) UnmarshalYAML

func (c *GroupConfig) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML helps to unmarshal a GroupConfig object from YAML.

type InstanceConfig

type InstanceConfig struct {
	// RawConfig is a raw configuration of the instance scope.
	RawConfig *Config `yaml:"-"`
}

InstanceConfig describes an instance configuration.

func GetInstanceConfig

func GetInstanceConfig(cluster ClusterConfig, instance string) (InstanceConfig, error)

GetInstanceConfig returns a full configuration for an instance with the name from a cluster config. It merges the configuration from all configured sources and scopes: environment, global, group, replicaset, instance.

func MakeInstanceConfig

func MakeInstanceConfig(config *Config) (InstanceConfig, error)

MakeInstanceConfig creates an InstanceConfig object from a configuration.

func (*InstanceConfig) UnmarshalYAML

func (c *InstanceConfig) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML helps to unmarshal an InstanceConfig object from YAML.

type ReplicasetConfig

type ReplicasetConfig struct {
	// RawConfig is a raw configuration of the replicaset scope.
	RawConfig *Config `yaml:"-"`
	// Instances are configurations at an instance scope.
	Instances map[string]InstanceConfig
}

ReplicasetConfig describes a replicaset configuration.

func (*ReplicasetConfig) UnmarshalYAML

func (c *ReplicasetConfig) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML helps to unmarshal a ReplicasetConfig object from YAML.

type YamlCollector

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

YamlCollector collects a configuration from YAML data.

func NewYamlCollector

func NewYamlCollector(data []byte) YamlCollector

NewYamlCollector create a new YAML collector.

func (YamlCollector) Collect

func (c YamlCollector) Collect() (*Config, error)

Collect collects a configuration from YAML data.

Jump to

Keyboard shortcuts

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