config

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: GPL-3.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(c *Config, name string) bool

Bool reads a configuration value from c by name and casts it to bool.

Panics if the value can not be casted.

func BoolSafe

func BoolSafe(c *Config, name string) bool

BoolSafe reads a configuration value from c by name and casts it to bool.

Returns false if the value can not be casted.

func Duration

func Duration(c *Config, name string) time.Duration

Duration reads a configuration value from c by name and casts it to time.Duration.

Panics if the value can not be casted.

func DurationSafe

func DurationSafe(c *Config, name string) time.Duration

DurationSafe reads a configuration value from c by name and casts it to time.Duration.

Returns 0 if the value can not be casted.

func Int

func Int(c *Config, name string) int64

Int reads a configuration value from c by name and casts it to int64.

Panics if the value can not be casted.

func IntSafe

func IntSafe(c *Config, name string) int64

IntSafe reads a configuration value from c by name and casts it to int64.

Returns 0 if the value can not be casted.

func SizeInBytesSafe added in v0.26.0

func SizeInBytesSafe(c *Config, name string) uint64

SizeInBytesSafe reads a configuration value from c by name and casts it to size in bytes (uint64).

The suffix can be single-letter (b, k, m, g, t) or with an additional b at the end. Spaces between the number and the suffix are allowed. All multipliers are power of 2 (i.e. k is for kibi-byte).

Returns 0 if a value can't be casted.

func String

func String(c *Config, name string) string

String reads a configuration value from c by name and casts it to a string.

Panics if the value can not be casted.

func StringSafe

func StringSafe(c *Config, name string) string

StringSafe reads a configuration value from c by name and casts it to a string.

Returns "" if the value can not be casted.

func StringSlice

func StringSlice(c *Config, name string) []string

StringSlice reads a configuration value from c by name and casts it to a []string.

Panics if the value can not be casted.

func StringSliceSafe

func StringSliceSafe(c *Config, name string) []string

StringSliceSafe reads a configuration value from c by name and casts it to a []string.

Returns nil if the value can not be casted.

func Uint

func Uint(c *Config, name string) uint64

Uint reads a configuration value from c by name and casts it to uint64.

Panics if the value can not be casted.

func Uint32 added in v0.25.0

func Uint32(c *Config, name string) uint32

Uint32 reads a configuration value from c by name and casts it to uint32.

Panics if the value can not be casted.

func Uint32Safe added in v0.25.0

func Uint32Safe(c *Config, name string) uint32

Uint32Safe reads a configuration value from c by name and casts it to uint32.

Returns 0 if the value can not be casted.

func UintSafe

func UintSafe(c *Config, name string) uint64

UintSafe reads a configuration value from c by name and casts it to uint64.

Returns 0 if the value can not be casted.

Types

type Config

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

Config represents a group of named values structured by tree type.

Sub-trees are named configuration sub-sections, leaves are named configuration values. Names are of string type.

func New

func New(_ Prm, opts ...Option) *Config

New creates a new Config instance.

If file option is provided (WithConfigFile), configuration values are read from it. Otherwise, Config is a degenerate tree.

func (*Config) SetDefault added in v0.26.1

func (x *Config) SetDefault(from *Config)

SetDefault sets fallback config for missing values.

It supports only one level of nesting and is intended to be used to provide default values.

func (*Config) Sub

func (x *Config) Sub(name string) *Config

Sub returns a subsection of the Config by name.

Returns nil if subsection is missing.

func (*Config) Value

func (x *Config) Value(name string) interface{}

Value returns the configuration value by name.

Result can be casted to a particular type via corresponding function (e.g. StringSlice). Note: casting via Go `.()` operator is not recommended.

Returns nil if config is nil.

type Option

type Option func(*opts)

Option allows to set an optional parameter of the Config.

func WithConfigFile

func WithConfigFile(path string) Option

WithConfigFile returns an option to set the system path to the configuration file.

type Prm

type Prm struct{}

Prm groups required parameters of the Config.

Jump to

Keyboard shortcuts

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