Documentation ¶
Index ¶
- Constants
- Variables
- func ConnectEtcd(opts EtcdOpts) (*clientv3.Client, error)
- func HasInstance(cluster ClusterConfig, name string) bool
- func Instances(cluster ClusterConfig) []string
- func Validate(config *Config, schema []SchemaPath) error
- type AllowedValidator
- type AnyValidator
- type ArrayValidator
- type BooleanValidator
- type ClusterConfig
- type Collector
- type Config
- func (config *Config) Elems(path []string) ([]string, error)
- func (config *Config) ForEach(path []string, fun func(path []string, value any))
- func (config *Config) Get(path []string) (any, error)
- func (config *Config) Merge(low *Config)
- func (config *Config) Set(path []string, value any) error
- func (config *Config) String() string
- func (config *Config) UnmarshalYAML(unmarshal func(any) error) error
- type ConfigPublisher
- type DataPublisher
- type EnvCollector
- type EtcdCollector
- type EtcdDataPublisher
- type EtcdGetter
- type EtcdOpts
- type EtcdTxnGetter
- type FileCollector
- type FileDataPublisher
- type GroupConfig
- type InstanceConfig
- type IntegerValidator
- type MapValidator
- type NotExistError
- type NumberValidator
- type RecordValidator
- type ReplicasetConfig
- type SchemaPath
- type SequenceValidator
- type StringValidator
- type ValidateError
- type Validator
- type YamlCollector
- type YamlConfigPublisher
Constants ¶
const (
DefaultEtcdTimeout = 3 * time.Second
)
Variables ¶
var ConfigEnvPaths = [][]string{}/* 162 elements not displayed */
var TarantoolSchema = []SchemaPath{}/* 162 elements not displayed */
Functions ¶
func ConnectEtcd ¶ added in v1.3.0
ConnectEtcd creates a new client object for a etcd from the specified options.
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.
func Validate ¶ added in v1.3.0
func Validate(config *Config, schema []SchemaPath) error
Validate validates a configuration with the schema.
Types ¶
type AllowedValidator ¶ added in v1.3.0
type AllowedValidator struct {
// contains filtered or unexported fields
}
AllowedValidator allows a set of values.
func MakeAllowedValidator ¶ added in v1.3.0
func MakeAllowedValidator(validator Validator, allowed []any) AllowedValidator
MakeAllowedValidator creates a new AllowedValidator object.
type AnyValidator ¶ added in v1.3.0
type AnyValidator struct { }
AnyValidator allows any values, but not nil.
type ArrayValidator ¶ added in v1.3.0
type ArrayValidator struct {
// contains filtered or unexported fields
}
ArrayValidator allows an array of values.
func MakeArrayValidator ¶ added in v1.3.0
func MakeArrayValidator(itemValidator Validator) ArrayValidator
MakeArrayValidator create a new ArrayValidator object with a validator for values.
type BooleanValidator ¶ added in v1.3.0
type BooleanValidator struct { }
BooleanValidator allows only boolean-compatible values.
type ClusterConfig ¶
type ClusterConfig struct { Config struct { Etcd struct { Endpoints []string `yaml:"endpoints"` Username string `yaml:"username"` Password string `yaml:"password"` Prefix string `yaml:"prefix"` Ssl struct { KeyFile string `yaml:"ssl_key"` CertFile string `yaml:"cert_file"` CaPath string `yaml:"ca_path"` CaFile string `yaml:"ca_file"` VerifyPeer bool `yaml:"verify_peer"` VerifyHost bool `yaml:"verify_host"` } `yaml:"ssl"` Http struct { Request struct { Timeout float64 `yaml:"timeout"` } `yaml:"request"` } `yaml:"http"` } `yaml:"etcd"` } `yaml:"config"` // 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 ReplaceInstanceConfig ¶ added in v1.3.0
func ReplaceInstanceConfig(cconfig ClusterConfig, instance string, iconfig *Config) (ClusterConfig, error)
ReplaceInstanceConfig replaces an instance configuration.
func (*ClusterConfig) UnmarshalYAML ¶
func (config *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 (*Config) Merge ¶
Merge merges a configuration to the current. The outside configuration has a low priority.
type ConfigPublisher ¶ added in v1.3.0
type ConfigPublisher interface { // Publish publisher the configuration or returns an error. Publish(config *Config) error }
ConfigPublisher interface must be implemented by a config publisher.
type DataPublisher ¶ added in v1.3.0
type DataPublisher interface { // Publish publishes the data or returns an error. Publish(data []byte) error }
DataPublisher interface must be implemented by a raw data publisher.
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 (collector EnvCollector) Collect() (*Config, error)
Collect collects a configuration from environment variables.
type EtcdCollector ¶ added in v1.3.0
type EtcdCollector struct {
// contains filtered or unexported fields
}
EtcdCollector collects data from a etcd connection.
func NewEtcdCollector ¶ added in v1.3.0
func NewEtcdCollector(getter EtcdGetter, prefix string, timeout time.Duration) EtcdCollector
NewEtcdCollector creates a new collector for etcd from the path.
func (EtcdCollector) Collect ¶ added in v1.3.0
func (collector EtcdCollector) Collect() (*Config, error)
Collect collects a configuration from the specified path with the specified timeout.
type EtcdDataPublisher ¶ added in v1.3.0
type EtcdDataPublisher struct {
// contains filtered or unexported fields
}
EtcdDataPublisher publishes a data into etcd.
func NewEtcdDataPublisher ¶ added in v1.3.0
func NewEtcdDataPublisher(getter EtcdTxnGetter, prefix string, timeout time.Duration) EtcdDataPublisher
NewEtcdDataPublisher creates a new EtcdDataPublisher object to publish a data to etcd with the prefix during the timeout.
func (EtcdDataPublisher) Publish ¶ added in v1.3.0
func (publisher EtcdDataPublisher) Publish(data []byte) error
Publish publishes the configuration into etcd to the given prefix.
type EtcdGetter ¶ added in v1.3.0
type EtcdGetter interface { // Get retrieves key-value pairs for a key. Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error) }
EtcdGetter is the interface that wraps get from etcd method.
type EtcdOpts ¶ added in v1.3.0
type EtcdOpts struct { // Endpoints a slice of endpoints to connect. Endpoints []string // Prefix is a configuration prefix. Prefix string // Username is a user name for authorization Username string // Password is a password for authorization Password string // KeyFile is a path to a private SSL key file. KeyFile string // CertFile is a path to an SSL certificate file. CertFile string // CaPath is a path to a trusted certificate authorities (CA) directory. CaPath string // CaFile is a path to a trusted certificate authorities (CA) file. CaFile string // SkipHostVerify controls whether a client verifies the server's // certificate chain and host name. This is dangerous option so by // default it is false. SkipHostVerify bool // Timeout is a timeout for actions. Timeout time.Duration }
EtcdOpts is a way to configure a etcd client.
type EtcdTxnGetter ¶ added in v1.3.0
type EtcdTxnGetter interface { EtcdGetter // Txn creates a transaction. Txn(ctx context.Context) clientv3.Txn }
EtcdUpdater is the interface that adds Txn method to EtcdGetter.
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 (collector FileCollector) Collect() (*Config, error)
Collect collects a configuration from a file located at a specified path.
type FileDataPublisher ¶ added in v1.3.0
type FileDataPublisher struct {
// contains filtered or unexported fields
}
FileDataPublisher publishes a data into a file as is.
func NewFileDataPublisher ¶ added in v1.3.0
func NewFileDataPublisher(path string) FileDataPublisher
NewFileDataPublisher creates a new FileDataPublisher object to publish a data into a file for the given path.
func (FileDataPublisher) Publish ¶ added in v1.3.0
func (publisher FileDataPublisher) Publish(data []byte) error
Publish publishes the data to a file for the given 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 (config *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 (config *InstanceConfig) UnmarshalYAML(unmarshal func(any) error) error
UnmarshalYAML helps to unmarshal an InstanceConfig object from YAML.
type IntegerValidator ¶ added in v1.3.0
type IntegerValidator struct { }
IntegerValidator allows only integer-compatible values.
type MapValidator ¶ added in v1.3.0
type MapValidator struct {
// contains filtered or unexported fields
}
MapValidator allows only a map.
func MakeMapValidator ¶ added in v1.3.0
func MakeMapValidator(key Validator, value Validator) MapValidator
MakeMapValidator create a new MapValidator object with specified a key and a value validator.
type NotExistError ¶ added in v1.3.0
type NotExistError struct {
// contains filtered or unexported fields
}
NotExistError error type for non-existing path.
func (NotExistError) Error ¶ added in v1.3.0
func (e NotExistError) Error() string
Error - error interface implementation for NotExistError.
type NumberValidator ¶ added in v1.3.0
type NumberValidator struct { }
NumberValidator allows only number-compatible values.
type RecordValidator ¶ added in v1.3.0
type RecordValidator struct {
// contains filtered or unexported fields
}
RecordValidator allows only a record values.
func MakeRecordValidator ¶ added in v1.3.0
func MakeRecordValidator(items map[string]Validator) RecordValidator
MakeRecordValidator create a new RecordValidator object with a specified record schema.
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 (config *ReplicasetConfig) UnmarshalYAML(unmarshal func(any) error) error
UnmarshalYAML helps to unmarshal a ReplicasetConfig object from YAML.
type SchemaPath ¶ added in v1.3.0
type SchemaPath struct { // Path of a configuration value. Path []string // Validator to validate the configuration value. Validator Validator }
SchemaPath describes a validation schema for a configuration.
type SequenceValidator ¶ added in v1.3.0
type SequenceValidator struct {
// contains filtered or unexported fields
}
SequenceValidator allows to combine validators in a sequence.
func MakeSequenceValidator ¶ added in v1.3.0
func MakeSequenceValidator(validators ...Validator) SequenceValidator
MakeSequenceValidator creates a new SequenceValidator object.
type StringValidator ¶ added in v1.3.0
type StringValidator struct { }
StringValidator allows only string-compatible values.
type ValidateError ¶ added in v1.3.0
type ValidateError struct {
// contains filtered or unexported fields
}
ValidateError describes a schema validation error.
func (ValidateError) Error ¶ added in v1.3.0
func (err ValidateError) Error() string
Error returns a string representation of the validation error.
func (ValidateError) Path ¶ added in v1.3.0
func (err ValidateError) Path() []string
Path returns a schema path to a configuration value.
func (ValidateError) Unwrap ¶ added in v1.3.0
func (err ValidateError) Unwrap() []error
Error returns a list of errors for the corresponding path.
type Validator ¶ added in v1.3.0
type Validator interface { // Validate validates the value and returns a validated one. Validate(value any) (any, error) }
Validator validates a value.
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 (collector YamlCollector) Collect() (*Config, error)
Collect collects a configuration from YAML data.
type YamlConfigPublisher ¶ added in v1.3.0
type YamlConfigPublisher struct {
// contains filtered or unexported fields
}
YamlConfigPublisher publishes a configuration as YAML via the base publisher.
func NewYamlConfigPublisher ¶ added in v1.3.0
func NewYamlConfigPublisher(publisher DataPublisher) YamlConfigPublisher
NewYamlConfigPublisher creates a new YamlConfigPublisher object to publish a configuration via the publisher.
func (YamlConfigPublisher) Publish ¶ added in v1.3.0
func (publisher YamlConfigPublisher) Publish(config *Config) error
Publish publishes the configuration as YAML data.