config

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: Apache-2.0 Imports: 9 Imported by: 582

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyLoggingMask

func ApplyLoggingMask(c interface{})

ApplyLoggingMask redacts the values of keys that might contain sensitive data (password, passphrase, etc.).

func ConfigOverwriteFlag

func ConfigOverwriteFlag(
	fs *flag.FlagSet,
	config *C,
	name, path, def, usage string,
) *string

ConfigOverwriteFlag defines a new flag updating a setting in an Config object. The name is used as the flag its name the path parameter is the full setting name to be used when the flag is set.

func DebugString

func DebugString(c *C, filterPrivate bool) string

DebugString prints a human readable representation of the underlying config using JSON formatting.

func OverwriteConfigOpts

func OverwriteConfigOpts(options []ucfg.Option)

OverwriteConfigOpts allow to change the globally set config option

func SettingVarFlag

func SettingVarFlag(fs *flag.FlagSet, def *C, name, usage string)

SettingVarFlag defines a setting flag, name and it's usage. Settings are applied to the Config object passed.

Types

type C

type C ucfg.Config

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

func MergeConfigs

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

MergeConfigs merges the configs together. If there are different values for the same key, the last one always overwrites the previous values.

func MergeConfigsWithOptions

func MergeConfigsWithOptions(cfgs []*C, options ...ucfg.Option) (*C, error)

MergeConfigs merges the configs together based on the provided opts. If there are different values for the same key, the last one always overwrites the previous values.

func MustNewConfigFrom

func MustNewConfigFrom(from interface{}) *C

MustNewConfigFrom creates a new C object from the given input. From can be any kind of structured data (struct, map, array, slice).

If from is a string, the contents is treated like raw YAML input. The string will be parsed and a structure config object is build from the parsed result.

MustNewConfigFrom panics if an error occurs.

func NewConfig

func NewConfig() *C

func NewConfigFrom

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

NewConfigFrom creates a new C object from the given input. From can be any kind of structured data (struct, map, array, slice).

If from is a string, the contents is treated like raw YAML input. The string will be parsed and a structure config object is build from the parsed result.

func NewConfigWithYAML

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

NewConfigWithYAML reads a YAML configuration.

func SettingFlag

func SettingFlag(fs *flag.FlagSet, name, usage string) *C

SettingFlag defines a setting flag, name and it's usage. The return value is the Config object settings are applied to.

func (*C) Bool

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

func (*C) Child

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

func (*C) CountField

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

func (*C) Enabled

func (c *C) Enabled() bool

Enabled return the configured enabled value or true by default.

func (*C) FlattenedKeys

func (c *C) FlattenedKeys() []string

FlattenedKeys return a sorted flattened views of the set keys in the configuration.

func (*C) Float

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

func (*C) GetFields

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

GetFields returns the list of fields in the configuration.

func (*C) Has

func (c *C) Has(name string, idx int) (bool, error)

func (*C) HasField

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

func (*C) Int

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

func (*C) IsArray

func (c *C) IsArray() bool

func (*C) IsDict

func (c *C) IsDict() bool

func (*C) Merge

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

Merge merges the parameter into the C object.

func (*C) MergeWithOpts

func (c *C) MergeWithOpts(from interface{}, opts ...ucfg.Option) error

Merge merges the parameter into the C object based on the provided options.

func (*C) Path

func (c *C) Path() string

func (*C) PathOf

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

func (*C) Remove

func (c *C) Remove(name string, idx int) (bool, error)

func (*C) SetBool

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

func (*C) SetChild

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

func (*C) SetFloat

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

func (*C) SetInt

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

func (*C) SetString

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

func (*C) String

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

func (*C) Unpack

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

type Namespace

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

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

func (*Namespace) Config

func (ns *Namespace) Config() *C

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) Unpack

func (ns *Namespace) Unpack(cfg *C) error

Unpack unpacks a configuration with at most one sub object. An sub object is ignored if it is disabled by setting `enabled: false`. If the configuration passed contains multiple active sub objects, Unpack will return an error.

type SettingsFlag

type SettingsFlag cfgflag.FlagValue

SettingsFlag captures key/values pairs into an Config object. The flag backed by SettingsFlag can be used multiple times. Values are overwritten by the last usage of a key.

func NewSettingsFlag

func NewSettingsFlag(def *C) *SettingsFlag

NewSettingsFlag creates a new SettingsFlag instance, not registered with any FlagSet.

func (*SettingsFlag) Config

func (f *SettingsFlag) Config() *C

Config returns the config object the SettingsFlag stores applied settings to.

func (*SettingsFlag) Get

func (f *SettingsFlag) Get() interface{}

Get returns the Config object used to store values.

func (*SettingsFlag) Set

func (f *SettingsFlag) Set(s string) error

Set sets a settings value in the Config object. The input string must be a key-value pair like `key=value`. If the value is missing, the value is set to the boolean value `true`.

func (*SettingsFlag) String

func (f *SettingsFlag) String() string

String always returns an empty string. It is required to fulfill the flag.Value interface.

func (*SettingsFlag) Type

func (f *SettingsFlag) Type() string

Type reports the type of contents (setting=value) expected to be parsed by Set. It is used to build the CLI usage string.

type StringsFlag

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

StringsFlag collects multiple usages of the same flag into an array of strings. Duplicate values will be ignored.

func NewStringsFlag

func NewStringsFlag(arr *[]string) *StringsFlag

NewStringsFlag creates a new, but unregistered StringsFlag instance. Results of the flag usage will be appended to `arr`. If the slice is not initially empty, its first value will be used as default. If the flag is used, the slice will be emptied first.

func StringArrFlag

func StringArrFlag(fs *flag.FlagSet, name, def, usage string) *StringsFlag

StringArrFlag creates and registers a new StringsFlag with the given FlagSet. If no FlagSet is passed, flag.CommandLine will be used as target FlagSet.

func StringArrVarFlag

func StringArrVarFlag(fs *flag.FlagSet, arr *[]string, name, usage string) *StringsFlag

StringArrVarFlag creates and registers a new StringsFlag with the given FlagSet. Results of the flag usage will be appended to `arr`. If the slice is not initially empty, its first value will be used as default. If the flag is used, the slice will be emptied first. If no FlagSet is passed, flag.CommandLine will be used as target FlagSet.

func (*StringsFlag) Get

func (f *StringsFlag) Get() interface{}

Get returns the backing slice its contents as interface{}. The type used is `[]string`.

func (*StringsFlag) List

func (f *StringsFlag) List() []string

List returns the current set values.

func (*StringsFlag) Register

func (f *StringsFlag) Register(fs *flag.FlagSet, name, usage string)

Register registers the StringsFlag instance with a FlagSet. A valid FlagSet must be used. Register panics if the flag is already registered.

func (*StringsFlag) Set

func (f *StringsFlag) Set(v string) error

Set is used to pass usage of the flag to StringsFlag. Set adds the new value to the backing array. The array will be emptied on Set, if the backing array still contains the default value.

func (*StringsFlag) SetDefault

func (f *StringsFlag) SetDefault(v string)

SetDefault sets the flags new default value. This overwrites the contents in the backing array.

func (*StringsFlag) String

func (f *StringsFlag) String() string

String joins all it's values set into a comma-separated string.

func (*StringsFlag) Type

func (f *StringsFlag) Type() string

Type reports the type of contents (string) expected to be parsed by Set. It is used to build the CLI usage string.

Jump to

Keyboard shortcuts

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