config

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: GPL-3.0 Imports: 7 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 configuration value from c by name and casts it to bool.

Panics if value can not be casted.

func BoolSafe

func BoolSafe(c *Config, name string) bool

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

Returns false if value can not be casted.

func DebugValue

func DebugValue(c *Config, name string) interface{}

DebugValue returns debug configuration value.

Returns nil if misc.Debug is not set to "true".

func Duration

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

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

Panics if value can not be casted.

func DurationSafe

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

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

Returns 0 if value can not be casted.

func Int

func Int(c *Config, name string) int64

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

Panics if value can not be casted.

func IntSafe

func IntSafe(c *Config, name string) int64

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

Returns 0 if value can not be casted.

func String

func String(c *Config, name string) string

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

Panics if value can not be casted.

func StringSafe

func StringSafe(c *Config, name string) string

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

Returns "" if value can not be casted.

func StringSlice

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

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

Panics if value can not be casted.

func StringSliceSafe

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

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

Returns nil if value can not be casted.

func Uint

func Uint(c *Config, name string) uint64

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

Panics if value can not be casted.

func UintSafe

func UintSafe(c *Config, name string) uint64

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

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

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

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

Sub returns subsection of the Config by name.

Returns nil if subsection if missing.

func (*Config) Value

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

Value returns 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 optional parameter of the Config.

func WithConfigFile

func WithConfigFile(path string) Option

WithConfigFile returns option to set 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