Documentation ¶
Index ¶
- func Bool(c *Config, name string) bool
- func BoolSafe(c *Config, name string) bool
- func DebugValue(c *Config, name string) interface{}
- func Duration(c *Config, name string) time.Duration
- func DurationSafe(c *Config, name string) time.Duration
- func Int(c *Config, name string) int64
- func IntSafe(c *Config, name string) int64
- func SizeInBytesSafe(c *Config, name string) uint64
- func String(c *Config, name string) string
- func StringSafe(c *Config, name string) string
- func StringSlice(c *Config, name string) []string
- func StringSliceSafe(c *Config, name string) []string
- func Uint(c *Config, name string) uint64
- func Uint32(c *Config, name string) uint32
- func Uint32Safe(c *Config, name string) uint32
- func UintSafe(c *Config, name string) uint64
- type Config
- type Option
- type Prm
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool reads configuration value from c by name and casts it to bool.
Panics if value can not be casted.
func BoolSafe ¶
BoolSafe reads configuration value from c by name and casts it to bool.
Returns false if value can not be casted.
func DebugValue ¶
DebugValue returns debug configuration value.
Returns nil if misc.Debug is not set to "true".
func Duration ¶
Duration reads configuration value from c by name and casts it to time.Duration.
Panics if value can not be casted.
func DurationSafe ¶
DurationSafe reads configuration value from c by name and casts it to time.Duration.
Returns 0 if value can not be casted.
func Int ¶
Int reads configuration value from c by name and casts it to int64.
Panics if value can not be casted.
func IntSafe ¶
IntSafe reads configuration value from c by name and casts it to int64.
Returns 0 if value can not be casted.
func SizeInBytesSafe ¶ added in v0.26.0
SizeInBytesSafe reads 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 ¶
String reads configuration value from c by name and casts it to string.
Panics if value can not be casted.
func StringSafe ¶
StringSafe reads configuration value from c by name and casts it to string.
Returns "" if value can not be casted.
func StringSlice ¶
StringSlice reads configuration value from c by name and casts it to []string.
Panics if value can not be casted.
func StringSliceSafe ¶
StringSliceSafe reads configuration value from c by name and casts it to []string.
Returns nil if value can not be casted.
func Uint ¶
Uint reads configuration value from c by name and casts it to uint64.
Panics if value can not be casted.
func Uint32 ¶ added in v0.25.0
Uint32 reads configuration value from c by name and casts it to uint32.
Panics if value can not be casted.
func Uint32Safe ¶ added in v0.25.0
Uint32Safe reads configuration value from c by name and casts it to uint32.
Returns 0 if 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 ¶
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
SetDefault sets fallback config for missing values.
It supports only one level of nesting and is intended to be used to provide default values.
type Option ¶
type Option func(*opts)
Option allows to set optional parameter of the Config.
func WithConfigFile ¶
WithConfigFile returns option to set system path to the configuration file.