func Init() { cfgFile := getAbs("./settings/settings.ini") cfg := new(ini.File) cfg.BlockMode = false cfg, err := ini.Load(cfgFile) if err != nil { panic(err) } cfg.MapTo(&settingStruct) settingStruct.Log.File = filepath.Join( getAbs(settingStruct.Log.Path), time.Now().Format(settingStruct.Log.Format), ) //map to global { Static = settingStruct.Static Server = settingStruct.Server Filesync = settingStruct.Filesync Template = settingStruct.Template DefaultVars = settingStruct.DefaultVars Admin = settingStruct.Admin Log = settingStruct.Log } FsCfgMgr = new(cfgMgr) FsCfgMgr.Init() go watch() }
// Loads the primary configuration file and maps it into a Config type. func parseConfigINI(cfgPathAbs string) (*Config, error) { var err error var cfg *Config = new(Config) var iniCfg *ini.File // loading the INI file contents into local struct if iniCfg, err = ini.Load(cfgPathAbs); err != nil { log.Fatalln("[Config] Errors on parsing INI file:", err) return nil, err } // mapping configuration into local struct if err = iniCfg.MapTo(cfg); err != nil { log.Fatalln("[Config] Errors on mapping INI:", err) return nil, err } return cfg, nil }