2021-10-27 14:45:36 +00:00
|
|
|
package bootstrap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Xhofe/alist/conf"
|
|
|
|
"github.com/Xhofe/alist/utils"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"io/ioutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
// InitConf init config
|
|
|
|
func InitConf() {
|
|
|
|
log.Infof("reading config file: %s", conf.ConfigFile)
|
|
|
|
if !utils.Exists(conf.ConfigFile) {
|
|
|
|
log.Infof("config file not exists, creating default config file")
|
2021-11-13 06:23:41 +00:00
|
|
|
_, err := utils.CreatNestedFile(conf.ConfigFile)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("failed to create config file")
|
|
|
|
}
|
2021-10-27 14:45:36 +00:00
|
|
|
conf.Conf = conf.DefaultConfig()
|
|
|
|
if !utils.WriteToJson(conf.ConfigFile, conf.Conf) {
|
|
|
|
log.Fatalf("failed to create default config file")
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
config, err := ioutil.ReadFile(conf.ConfigFile)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("reading config file error:%s", err.Error())
|
|
|
|
}
|
|
|
|
conf.Conf = new(conf.Config)
|
2022-01-03 12:25:22 +00:00
|
|
|
err = utils.Json.Unmarshal(config, conf.Conf)
|
2021-10-27 14:45:36 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("load config error: %s", err.Error())
|
|
|
|
}
|
|
|
|
log.Debugf("config:%+v", conf.Conf)
|
|
|
|
}
|