gosuki/config.go

44 lines
964 B
Go
Raw Normal View History

2019-02-26 18:41:02 +00:00
package main
import (
2020-11-06 17:50:36 +00:00
"git.sp4ke.xyz/sp4ke/gomark/config"
"git.sp4ke.xyz/sp4ke/gomark/utils"
2019-02-27 10:47:06 +00:00
)
2019-02-26 18:41:02 +00:00
func initDefaultConfig() {
2019-02-27 10:47:06 +00:00
//TODO: handle chrome
2019-02-26 18:41:02 +00:00
log.Debug("Creating default config on config.toml")
2019-02-27 10:47:06 +00:00
err := config.InitConfigFile()
2019-02-26 18:41:02 +00:00
if err != nil {
log.Fatal(err)
}
}
// FIX: make config init manual from main package
// HACK: this section is called well before module options/config parameters are
// initialized
func initConfig() {
log.Debugf("initializing config")
2019-02-27 10:47:06 +00:00
// Check if config file exists
exists, err := utils.CheckFileExists(config.ConfigFile)
if err != nil {
log.Fatal(err)
}
if !exists {
// Initialize default initConfig
//NOTE: if custom flags are passed before config.toml exists, falg
//options will not be saved to the initial config.toml, this means
//command line flags have higher priority than config.toml
initDefaultConfig()
2019-02-27 10:47:06 +00:00
} else {
2019-02-27 16:09:33 +00:00
err = config.LoadFromTomlFile()
if err != nil {
log.Fatal(err)
}
2019-02-27 10:47:06 +00:00
}
2019-02-26 18:41:02 +00:00
}