config

package
v1.0.12-pre Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBool added in v1.10.0

func GetBool(s string) bool

func GetDuration added in v1.10.0

func GetDuration(s string) time.Duration

func GetInt added in v1.4.3

func GetInt(s string) int

func GetString

func GetString(s string, confmap ...map[string]string) string

Returns the configuration item as a string with ExpandString() applied, passing the first "confmap" if given

func GetStringMapString

func GetStringMapString(s string, confmap ...map[string]string) map[string]string

func GetStringSlice

func GetStringSlice(s string, confmap ...map[string]string) []string

func GetViper

func GetViper() *viper.Viper

func Set added in v1.5.0

func Set(s string, i interface{})

func SetDefault added in v1.10.0

func SetDefault(s string, i interface{})

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

The Config type acts as a container for local/extended viper instances

func GetConfig

func GetConfig() *Config

func (*Config) ExpandString

func (c *Config) ExpandString(input string, confmap map[string]string) (value string)

Return a string that has all contents of the form ${var} or $var expanded according to the following rules:

url - read the contents of the url, which can be a local file, as below:
	${file://path/to/file} - read the entire contents of the file, trim whitespace
	${https://host/path} - fetch the remote contents, trim whitespace. "http:" also supported.
${env:VARNAME} - replace with the contents of the environment varaible VARNAME, trim whitespace
${path.to.config} - and var containing a '.' will be looked up in global viper config space - this is NOT recursive
${name} - replace with the contents of confmap["name"] - trim whitespace

While the form $var is also supported but may be ambiguous and is not recommended.

If confmap is not given then environment variables are used directly.

Any errors result in an empty string being returned.

func (*Config) GetBool added in v1.10.0

func (c *Config) GetBool(s string) bool

func (*Config) GetDuration added in v1.10.0

func (c *Config) GetDuration(s string) time.Duration

func (*Config) GetInt added in v1.4.3

func (c *Config) GetInt(s string) int

func (*Config) GetString

func (c *Config) GetString(s string, confmap ...map[string]string) string

Returns the configuration item as a string with ExpandString() applied, passing the first "confmap" if given

func (*Config) GetStringMapString

func (c *Config) GetStringMapString(s string, confmap ...map[string]string) (m map[string]string)

func (*Config) GetStringSlice

func (c *Config) GetStringSlice(s string, confmap ...map[string]string) (slice []string)

func (*Config) GetViper

func (c *Config) GetViper() *viper.Viper

func (*Config) Set added in v1.10.0

func (c *Config) Set(s string, i interface{})

func (*Config) SetDefault added in v1.10.0

func (c *Config) SetDefault(s string, i interface{})

func (*Config) SetViper

func (c *Config) SetViper(v *viper.Viper)

Jump to

Keyboard shortcuts

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