Documentation ¶
Overview ¶
Package goconfig uses a struct as input and populates the fields of this struct with parameters fom command line, environment variables and configuration file.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Tag to set main name of field. Tag = "cfg" // TagDefault to set default value. TagDefault = "cfgDefault" // TagHelper to set usage help line. TagHelper = "cfgHelper" // Path sets default config path. Path string // File name of default config file. File string // FileRequired config file required. FileRequired bool // HelpString temporarily saves help. HelpString string // PrefixFlag is a string that would be placed at the beginning of the generated Flag tags. PrefixFlag string // PrefixEnv is a string that would be placed at the beginning of the generated Event tags. PrefixEnv string // ErrFileFormatNotDefined Is the error that is returned when there is no defined configuration file format. ErrFileFormatNotDefined = errors.New("file format not defined") Usage func() // Formats is the list of registered formats. Formats []Fileformat // FileEnv is the enviroment variable that define the config file. FileEnv string // PathEnv is the enviroment variable that define the config file path. PathEnv string // WatchConfigFile is the flag to update the config when the config file changes. WatchConfigFile bool // DisableFlags on the command line. DisableFlags bool )
Functions ¶
func Parse ¶
func Parse(config interface{}) (err error)
Parse configuration.
Example ¶
type config struct { Name string `cfg:"Name" cfgDefault:"root"` Value int `cfg:"Value" cfgDefault:"123"` } cfg := config{} err := Parse(&cfg) if err != nil { println(err) } println("Name:", cfg.Name, "Value:", cfg.Value)
Output:
func ParseAndWatch ¶ added in v1.4.2
ParseAndWatch configuration returns a channel for errors while watching files and anorther when each update has been detected.
Types ¶
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
ini_config_file
Example with configuration file.
|
Example with configuration file. |
json_config_file
Example with configuration file.
|
Example with configuration file. |
Click to show internal directories.
Click to hide internal directories.