package setting import ( "gopkg.in/ini.v1" "log" "time" ) type App struct { PrefixUrl string RuntimeRootPath string LogSavePath string LogSaveName string LogFileExt string TimeFormat string } var AppSetting = &App{} // 应用程序配置 type Server struct { RunMode string HttpPort int ReadTimeout time.Duration WriteTimeout time.Duration } var ServerSetting = &Server{} // Mssql数据库链接 type Database struct { Server string UserId string Password string Port int DataBase string Encrypt string } var DatabaseSetting = &Database{} var cfg *ini.File func Setup() { var err error cfg, err = ini.Load("conf/app.ini") if err != nil { log.Fatalf("setting.Setup, fail to parse 'conf/app.ini': %v", err) } mapTo("app", AppSetting) mapTo("server", ServerSetting) mapTo("database", DatabaseSetting) } func mapTo(section string, v interface{}) { err := cfg.Section(section).MapTo(v) if err != nil { log.Fatalf("Cfg.MapTo %s err: %v", section, err) } }