// LoadConfig - Loads config from YAML file
Loads config from YAML file
// LoadConfig - Loads config from YAML file
func LoadConfig(path string, createIfNotExist ...bool) (*Config, error) {
	createDefault := false
	if len(createIfNotExist) > 0 {
		createDefault = createIfNotExist[0]
	}
	if _, err := os.Open(path); err != nil {
		if os.IsNotExist(err) && createDefault {
			if err := GenerateConfig(path); err != nil {
				return nil, fmt.Errorf("can't create default config: %s", err)
			}
		} else {
			return nil, fmt.Errorf("config doesn't exist")
		}
	}
	confBytes, err := ioutil.ReadFile(path)
	if err != nil {
		return nil, err
	}
	conf := &Config{}
	if err := yaml.Unmarshal(confBytes, conf); err != nil {
		return nil, err
	}
	return conf, nil
}
func LoadConfig ( path string , createIfNotExist ... bool ) ( * Config , error ) { createDefault := false if len ( createIfNotExist ) > 0 { createDefault = createIfNotExist [ 0 ] } if _ , err := os . Open ( path ) ; err != nil { if os . IsNotExist ( err ) && createDefault { if err := GenerateConfig ( path ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } } else { return nil , fmt . Errorf ( " " ) } } confBytes , err := ioutil . ReadFile ( path ) if err != nil { return nil , err } conf := & Config { } if err := yaml . Unmarshal ( confBytes , conf ) ; err != nil { return nil , err } return conf , nil }
Loads config from YAML file
Loads config from YAML file
// Checking for config or creating default one // Reading config