func Initialize() { var err error beego.Info("thisi s is s ") var cac cache.Cache cac, err = cache.NewCache("memory", `{"interval":360}`) cachemanager.Cache = cac // session settings beego.BConfig.WebConfig.Session.SessionOn = true //beego.BConfig.WebConfig.Session.SessionProvider = Cfg.MustValue("session", "session_provider", "file") //beego.BConfig.WebConfig.Session.SessionProviderConfig = Cfg.MustValue("session", "session_path", "sessions") //beego.BConfig.WebConfig.Session.SessionName = Cfg.MustValue("session", "session_name", "wetalk_sess") //beego.BConfig.WebConfig.Session.SessionCookieLifeTime = Cfg.MustInt("session", "session_life_time", 0) //beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = Cfg.MustInt64("session", "session_gc_time", 86400) //load custom configurations loadConfig() //disable live reload for db connections PostgresConnection = beego.AppConfig.DefaultString(beego.BConfig.RunMode+"::"+"pg_conn", "user=postgres password=root dbname=eq sslmode=disable") PostgresMigrateConnection = beego.AppConfig.DefaultString(beego.BConfig.RunMode+"::"+"pg_migrate", "postgres://*****:*****@localhost:5432/test?sslmode=disable") // cache system Captcha = captcha.NewCaptcha("/captcha/", cac) Captcha.FieldIDName = "CaptchaId" Captcha.FieldCaptchaName = "Captcha" settingCompress() settingLocales() //watch conf files change configWatcher() if err != nil { beego.Error(err) } }
// LoadConfig loads configuration file. func LoadConfig() *goconfig.ConfigFile { var err error if fh, _ := os.OpenFile(AppConfPath, os.O_RDONLY|os.O_CREATE, 0600); fh != nil { fh.Close() } // Load configuration, set app version and log level. Cfg, err = goconfig.LoadConfigFile(GlobalConfPath) if Cfg == nil { Cfg, err = goconfig.LoadConfigFile(AppConfPath) if err != nil { fmt.Println("Fail to load configuration file: " + err.Error()) os.Exit(2) } } else { Cfg.AppendFiles(AppConfPath) } Cfg.BlockMode = false // set time zone of wetalk system TimeZone = Cfg.MustValue("app", "time_zone", "UTC") if _, err := time.LoadLocation(TimeZone); err == nil { os.Setenv("TZ", TimeZone) } else { fmt.Println("Wrong time_zone: " + TimeZone + " " + err.Error()) os.Exit(2) } // Trim 4th part. AppVer = strings.Join(strings.Split(APP_VER, ".")[:3], ".") beego.RunMode = Cfg.MustValue("app", "run_mode") beego.HttpPort = Cfg.MustInt("app", "http_port") IsProMode = beego.RunMode == "pro" if IsProMode { beego.SetLevel(beego.LevelInfo) } // cache system Cache, err = cache.NewCache("memory", `{"interval":360}`) Captcha = captcha.NewCaptcha("/captcha/", Cache) Captcha.FieldIdName = "CaptchaId" Captcha.FieldCaptchaName = "Captcha" // session settings beego.SessionOn = true beego.SessionProvider = Cfg.MustValue("session", "session_provider", "file") beego.SessionSavePath = Cfg.MustValue("session", "session_path", "sessions") beego.SessionName = Cfg.MustValue("session", "session_name", "wetalk_sess") beego.SessionCookieLifeTime = Cfg.MustInt("session", "session_life_time", 0) beego.SessionGCMaxLifetime = Cfg.MustInt64("session", "session_gc_time", 86400) beego.EnableXSRF = true // xsrf token expire time beego.XSRFExpire = 86400 * 365 driverName := Cfg.MustValue("orm", "driver_name", "mysql") dataSource := Cfg.MustValue("orm", "data_source", "root:root@/wetalk?charset=utf8&loc=UTC") maxIdle := Cfg.MustInt("orm", "max_idle_conn", 30) maxOpen := Cfg.MustInt("orm", "max_open_conn", 50) // set default database err = orm.RegisterDataBase("default", driverName, dataSource, maxIdle, maxOpen) if err != nil { beego.Error(err) } orm.RunCommand() err = orm.RunSyncdb("default", false, false) if err != nil { beego.Error(err) } reloadConfig() if SphinxEnabled { // for search config SphinxHost = Cfg.MustValue("search", "sphinx_host", "127.0.0.1:9306") SphinxMaxConn = Cfg.MustInt("search", "sphinx_max_conn", 5) orm.RegisterDriver("sphinx", orm.DR_MySQL) } social.DefaultAppUrl = AppUrl // OAuth var clientId, secret string clientId = Cfg.MustValue("oauth", "github_client_id", "your_client_id") secret = Cfg.MustValue("oauth", "github_client_secret", "your_client_secret") GithubAuth = apps.NewGithub(clientId, secret) clientId = Cfg.MustValue("oauth", "google_client_id", "your_client_id") secret = Cfg.MustValue("oauth", "google_client_secret", "your_client_secret") GoogleAuth = apps.NewGoogle(clientId, secret) err = social.RegisterProvider(GithubAuth) if err != nil { beego.Error(err) } err = social.RegisterProvider(GoogleAuth) if err != nil { beego.Error(err) } settingLocales() settingCompress() configWatcher() return Cfg }