Make configuration global, add helper functions
This commit is contained in:
parent
3c0254c9a1
commit
a4638db773
@ -23,8 +23,21 @@ var (
|
||||
DefaultConfig = Config{
|
||||
userAgent: initUserAgent(),
|
||||
}
|
||||
globalConfig *Config = NewConfig()
|
||||
)
|
||||
|
||||
func NewConfig() *Config {
|
||||
c := new(Config)
|
||||
c.userAgent = initUserAgent()
|
||||
c.Debug = false
|
||||
c.OutputFormat = "simple"
|
||||
return c
|
||||
}
|
||||
|
||||
func GetConfig() *Config {
|
||||
return globalConfig
|
||||
}
|
||||
|
||||
// Validate configuration struct
|
||||
func (c *Config) Validate() error {
|
||||
var err error
|
||||
@ -69,7 +82,7 @@ func (c *Config) MergeWithEnv() {
|
||||
|
||||
func LoadConfig(s string) (*Config, error) {
|
||||
var err error
|
||||
var c *Config = &Config{}
|
||||
var c *Config = GetConfig()
|
||||
|
||||
*c = DefaultConfig
|
||||
|
||||
@ -83,7 +96,7 @@ func LoadConfig(s string) (*Config, error) {
|
||||
func LoadConfigFile(configPath string) (*Config, error) {
|
||||
var err error
|
||||
|
||||
var c *Config = &Config{}
|
||||
var c *Config = GetConfig()
|
||||
|
||||
*c = DefaultConfig
|
||||
|
||||
|
@ -27,7 +27,7 @@ var BuildDate string
|
||||
var GitCommit string
|
||||
|
||||
func Main(args []string) (int, error) {
|
||||
var config *Config
|
||||
var config *Config = GetConfig()
|
||||
var err error
|
||||
var i int
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user