viper

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 5 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ViperConf

type ViperConf struct {
	// define config properties
	ConfigName                 string
	SpecificConfigFileFullPath string

	UseYAML            bool
	UseAutomaticEnvVar bool

	AppName                  string
	UseConfigPathEtcAppName  bool
	UseConfigPathHomeAppName bool
	CustomConfigPath         string
	// contains filtered or unexported fields
}

ViperConf struct info, ConfigName or SpecificConfigFileFullPath = One of the field is required UseYAML = true uses YAML; false uses JSON UseAutomaticEnvVar = true will auto load environment variables that matches to key AppName = used by config path options, identifies the name of the app UseConfig... = indicates config file search pattern

func (*ViperConf) Alias

func (v *ViperConf) Alias(key string, alias string) *ViperConf

Alias will create an alias for the related key, this allows the alias name and key name both refer to the same stored config data

func (*ViperConf) AllKeys

func (v *ViperConf) AllKeys() []string

AllKeys returns all keys in config file

func (*ViperConf) AllSettings

func (v *ViperConf) AllSettings() map[string]interface{}

AllSettings returns map of all settings in config file

func (*ViperConf) ConfigFileUsed

func (v *ViperConf) ConfigFileUsed() string

ConfigFileUsed returns the current config file full path in use

func (*ViperConf) Default

func (v *ViperConf) Default(key string, value interface{}) *ViperConf

Default will set default key value pairs, allows method chaining

func (*ViperConf) Get

func (v *ViperConf) Get(key string) interface{}

Get returns value by key

func (*ViperConf) GetBool

func (v *ViperConf) GetBool(key string) bool

GetBool returns value by key

func (*ViperConf) GetDuration

func (v *ViperConf) GetDuration(key string) time.Duration

GetDuration returns value by key

func (*ViperConf) GetFloat64

func (v *ViperConf) GetFloat64(key string) float64

GetFloat64 returns value by key

func (*ViperConf) GetInt

func (v *ViperConf) GetInt(key string) int

GetInt returns value by key

func (*ViperConf) GetInt64

func (v *ViperConf) GetInt64(key string) int64

GetInt64 returns value by key

func (*ViperConf) GetIntSlice

func (v *ViperConf) GetIntSlice(key string) []int

GetIntSlice returns value by key

func (*ViperConf) GetString

func (v *ViperConf) GetString(key string) string

GetString returns value by key

func (*ViperConf) GetStringMapInterface

func (v *ViperConf) GetStringMapInterface(key string) map[string]interface{}

GetStringMapInterface returns value by key

func (*ViperConf) GetStringMapString

func (v *ViperConf) GetStringMapString(key string) map[string]string

GetStringMapString returns value by key

func (*ViperConf) GetStringMapStringSlice

func (v *ViperConf) GetStringMapStringSlice(key string) map[string][]string

GetStringMapStringSlice returns value by key

func (*ViperConf) GetStringSlice

func (v *ViperConf) GetStringSlice(key string) []string

GetStringSlice returns value by key

func (*ViperConf) GetTime

func (v *ViperConf) GetTime(key string) time.Time

GetTime returns value by key

func (*ViperConf) Init

func (v *ViperConf) Init() (bool, error)

Init will initialize config and readInConfig if config file does not exist, false is returned

func (*ViperConf) IsDefined

func (v *ViperConf) IsDefined(key string) bool

IsDefined indicates if a key is defined within the config file

func (*ViperConf) IsSet

func (v *ViperConf) IsSet(key string) bool

IsSet indicates if a key's value was set within the config file

func (*ViperConf) Save

func (v *ViperConf) Save() error

Save will save the current config object into target config disk file

func (*ViperConf) Set

func (v *ViperConf) Set(key string, value interface{}) *ViperConf

Set will set key value pair into config object

func (*ViperConf) Size

func (v *ViperConf) Size(key string) int64

Size returns the given key's value in bytes

func (*ViperConf) SubConf

func (v *ViperConf) SubConf(key string) *ViperConf

SubConf returns a sub config object based on the given key

func (*ViperConf) Unmarshal

func (v *ViperConf) Unmarshal(outputStructPtr interface{}, key ...string) error

Unmarshal serializes config content into output struct, optionally serializes a portion of config identified by key into a struct

struct tag use `mapstructure:""` if struct tag refers to sub element of yaml, define struct to contain the sub elements

 	for example:
			parentkey:
				childkey: abc
				childkey_2: xyz
		type Child struct { ChildKey string `mapstructure:"childkey"`  ChildKey2 string `mapstructure:"childkey_2"` }
		type Parent struct { ChildData Child `mapstructure:"parentkey"`}

func (*ViperConf) WatchConfig

func (v *ViperConf) WatchConfig()

WatchConfig watches if config file does not exist, this call will panic

Jump to

Keyboard shortcuts

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