config

package
v0.38.5 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvPrefix is a prefix of ENV variables related
	// to storage node configuration.
	EnvPrefix = "FROSTFS"
)

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 FloatOrDefault added in v0.38.0

func FloatOrDefault(c *Config, name string, defaultValue float64) float64

FloatOrDefault reads a configuration value from c by name and casts it to float64.

Returns defaultValue 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

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

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

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(configFile, configDir, envPrefix string) *Config

New creates a new Config instance.

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

func (*Config) Reload

func (x *Config) Reload() error

Reload reads configuration path if it was provided to New.

func (*Config) SetDefault

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

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.

Jump to

Keyboard shortcuts

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