Documentation ¶
Index ¶
- func Bool(c *Config, name string) bool
- func BoolSafe(c *Config, name string) bool
- 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 a configuration value from c by name and casts it to bool.
Panics if the value can not be casted.
func BoolSafe ¶
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 ¶
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 ¶
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 ¶
Int reads a configuration value from c by name and casts it to int64.
Panics if the value can not be casted.
func IntSafe ¶
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
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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
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
Uint32Safe reads a configuration value from c by name and casts it to uint32.
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 ¶
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 an optional parameter of the Config.
func WithConfigFile ¶
WithConfigFile returns an option to set the system path to the configuration file.