config

package
v0.0.0-...-9a10968 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package config , actually copied from github.com/elastic/beats

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFlagOverwrite

func NewFlagOverwrite(
	set *flag.FlagSet,
	config *Config,
	name, path, def, usage string,
) *string

NewFlagOverwrite will use flags which specified

Types

type ClusterConfig

type ClusterConfig struct {
	Enabled         bool          `config:"enabled"`
	Name            string        `config:"name"`
	MinimumNodes    int           `config:"minimum_nodes"`
	Seeds           []string      `config:"seeds"`
	RPCConfig       RPCConfig     `config:"rpc"`
	BoradcastConfig NetworkConfig `config:"broadcast"`
}

ClusterConfig stores cluster settings

type Config

type Config ucfg.Config

Config object to store hierarchical configurations into. See https://godoc.org/github.com/elastic/go-ucfg#Config

func LoadFile

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

LoadFile will load config from specify file

func LoadFiles

func LoadFiles(paths ...string) (*Config, error)

LoadFiles will load configs from specify files

func MergeConfigs

func MergeConfigs(cfgs ...*Config) (*Config, error)

MergeConfigs just merge configs together

func NewConfig

func NewConfig() *Config

NewConfig create a pretty new config

func NewConfigFrom

func NewConfigFrom(from interface{}) (*Config, error)

NewConfigFrom get config instance

func NewConfigWithYAML

func NewConfigWithYAML(in []byte, source string) (*Config, error)

NewConfigWithYAML load config from yaml

func NewFlagConfig

func NewFlagConfig(
	set *flag.FlagSet,
	def *Config,
	name string,
	usage string,
) *Config

NewFlagConfig will use flags

func (*Config) Bool

func (c *Config) Bool(name string, idx int) (bool, error)

Bool reads a boolean setting returning an error if the setting has no boolean value.

func (*Config) Child

func (c *Config) Child(name string, idx int) (*Config, error)

Child returns a child configuration or an error if the setting requested is a primitive value only.

func (*Config) CountField

func (c *Config) CountField(name string) (int, error)

CountField returns number of entries in a table or 1 if entry is a primitive value. Primitives settings can be handled like a list with 1 entry.

func (*Config) Enabled

func (c *Config) Enabled(defaultV bool) bool

Enabled was a predefined config, enabled by default if no config was found

func (*Config) Float

func (c *Config) Float(name string, idx int) (float64, error)

Float reads a float64 value returning an error if the setting is not a float value or the primitive value is not convertible to float.

func (*Config) GetFields

func (c *Config) GetFields() []string

GetFields returns a list of all top-level named keys in c.

func (*Config) HasField

func (c *Config) HasField(name string) bool

HasField checks if c has a top-level named key name.

func (*Config) Int

func (c *Config) Int(name string, idx int) (int64, error)

Int reads an int64 value returning an error if the setting is not integer value, the primitive value is not convertible to int or a conversion would create an integer overflow.

func (*Config) IsArray

func (c *Config) IsArray() bool

IsArray checks if c has index only accessible settings.

func (*Config) IsDict

func (c *Config) IsDict() bool

IsDict checks if c has named keys.

func (*Config) Merge

func (c *Config) Merge(from interface{}) error

Merge a map, a slice, a struct or another Config object into c.

func (*Config) Path

func (c *Config) Path() string

Path gets the absolute path of c separated by sep. If c is a root-Config an empty string will be returned.

func (*Config) PathOf

func (c *Config) PathOf(field string) string

PathOf gets the absolute path of a potential setting field in c with name separated by sep.

func (*Config) SetBool

func (c *Config) SetBool(name string, idx int, value bool) error

SetBool sets a boolean primitive value. An error is returned if the new name is invalid.

func (*Config) SetChild

func (c *Config) SetChild(name string, idx int, value *Config) error

SetChild adds a sub-configuration. An error is returned if the name is invalid.

func (*Config) SetFloat

func (c *Config) SetFloat(name string, idx int, value float64) error

SetFloat sets an floating point primitive value. An error is returned if the name is invalid.

func (*Config) SetInt

func (c *Config) SetInt(name string, idx int, value int64) error

SetInt sets an integer primitive value. An error is returned if the new name is invalid.

func (*Config) SetString

func (c *Config) SetString(name string, idx int, value string) error

SetString sets string value. An error is returned if the name is invalid.

func (*Config) String

func (c *Config) String(name string, idx int) (string, error)

Strings reads a string setting returning an error if the setting has no string or primitive value convertible to string.

func (*Config) Unpack

func (c *Config) Unpack(to interface{}) error

Unpack unpacks c into a struct, a map, or a slice allocating maps, slices, and pointers as necessary.

type LoggingConfig

type LoggingConfig struct {
	RealtimePushEnabled  bool   `json:"realtime"`
	LogLevel             string `json:"log_level"`
	PushLogLevel         string `json:"push_log_level"`
	FuncFilterPattern    string `json:"func_pattern"`
	FileFilterPattern    string `json:"file_pattern"`
	MessageFilterPattern string `json:"message_pattern"`
	FileLoggingDisabled  bool   `json:"file_logging"`
}

LoggingConfig object to store logging related settings

type Namespace

type Namespace struct {
	C map[string]*Config `config:",inline"`
}

Namespace storing at most one configuration section by name and sub-section.

func (*Namespace) Config

func (ns *Namespace) Config() *Config

Config return the sub-configuration section if a section has been set.

func (*Namespace) IsSet

func (ns *Namespace) IsSet() bool

IsSet returns true if a sub-configuration section has been set.

func (*Namespace) Name

func (ns *Namespace) Name() string

Name returns the configuration sections it's name if a section has been set.

func (*Namespace) Validate

func (ns *Namespace) Validate() error

Validate checks at most one sub-namespace being set.

type NetworkConfig

type NetworkConfig struct {
	Host    string `config:"host"`
	Port    string `config:"port"`
	Binding string `config:"binding"`
}

NetworkConfig stores network settings

func (NetworkConfig) GetBindingAddr

func (cfg NetworkConfig) GetBindingAddr() string

type NodeConfig

type NodeConfig struct {
	Name string `config:"name"`
}

NodeConfig stores node settings

type PathConfig

type PathConfig struct {
	Data string `config:"data"`
	Log  string `config:"logs"`
	Cert string `config:"certs"`
}

PathConfig stores path settings

type RPCConfig

type RPCConfig struct {
	TLSConfig     TLSConfig     `config:"tls"`
	NetworkConfig NetworkConfig `config:"network"`
}

type Rule

type Rule struct {
	Contain []string `config:"contain"`
	Prefix  []string `config:"prefix"`
	Suffix  []string `config:"suffix"`
	Regex   []string `config:"regex"`
}

Rule is container of rules

type Rules

type Rules struct {
	Should  *Rule `config:"should"`
	Must    *Rule `config:"must"`
	MustNot *Rule `config:"must_not"`
}

Rules defines two fields, Should means any of the rules matched will be work Must means some rule must match MustNot means some rule must not match

type SystemConfig

type SystemConfig struct {
	ClusterConfig ClusterConfig `config:"cluster"`

	NodeConfig NodeConfig `config:"node"`

	PathConfig PathConfig `config:"path"`

	CookieSecret string `config:"cookie_secret"`

	AllowIndexCreation bool `config:"allow_index_creation"`

	AllowMultiInstance bool `config:"allow_multi_instance"`

	MaxNumOfInstance int `config:"max_num_of_instances"`

	Modules []*Config `config:"modules"`

	Plugins []*Config `config:"plugins"`
}

SystemConfig is a high priority config, init from the environment or startup, can't be changed on the fly, need to restart to make config apply

type TLSConfig

type TLSConfig struct {
	TLSEnabled            bool   `config:"enabled"`
	TLSCertFile           string `config:"cert_file"`
	TLSKeyFile            string `config:"key_file"`
	TLSInsecureSkipVerify bool   `config:"skip_insecure_verify"`
}

Jump to

Keyboard shortcuts

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