cfgx

package
v0.0.33 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package cfgx

This package provides functions to load configuration items in specified configuration file. The configuration file will be probed in the order of:

./sdp.conf
./conf/sdp.conf
./conf/sdp/sdp.conf
./cfg/sdp.conf
./cfg/sdp/sdp.conf
./etc/sdp.conf
./etc/sdp/sdp.conf
/etc/sdp.conf
/etc/sdp/sdp.conf
/user/local/etc/sdp.conf
/user/local/etc/sdp/sdp.conf

When one of the file in the above list is found, the rest of other files will be ignored.

We can use cfgx.AsInt() to parse configuration value as an int value. See cfgx.AsXxxx() for more information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsBool added in v0.0.14

func AsBool(key string, dst *bool, def bool) error

func AsDuration added in v0.0.14

func AsDuration(key string, dst *time.Duration, def time.Duration) error

func AsInt added in v0.0.14

func AsInt[T valuex.IntType](key string, dst *T, def T) error

func AsStr added in v0.0.14

func AsStr(key string, dst *string, def string) error

func AsStrArray added in v0.0.14

func AsStrArray(key string, dst *[]string, def []string) error

func AsUint added in v0.0.14

func AsUint[T valuex.UintType](key string, dst *T, def T) error

func PanicIf added in v0.0.14

func PanicIf[T any](ret T, src string, err error) (T, error)

PanicIf - Raise a panic or returns the given value. We can set values to Cfg.PanicWithError to enable/disable panic.

Types

type Config added in v0.0.14

type Config struct {
	// The user-specified configuration file name.
	// We can do parse os.args to pick the configuration file arguments.
	CfgFile string

	// Whether raise a panic when errors found or not. If PanicWithError is true
	// this module, cfgx, will raise a panic and exit the program when errors found.
	//
	// Otherwise, cfgx do nothing but returns a empty value set.
	PanicWithError bool
}
var (
	Cfg    *Config
	DefCfg = &Config{
		PanicWithError: true,
	}
)

Jump to

Keyboard shortcuts

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