示例#1
0
func init() {
	// Try to have highest performance.
	runtime.GOMAXPROCS(runtime.NumCPU())

	// Set application log level.
	if beego.AppConfig.String("runmode") == "pro" {
		beego.SetLevel(beego.LevelInfo)
	}

	beego.Info("Go Walker", VERSION)

	// ----- Initialize log file -----
	os.Mkdir("./log", os.ModePerm)
	filew := beego.NewFileWriter("log/log.log", true)
	err := filew.StartLogger()
	if err != nil {
		beego.Critical("NewFileWriter ->", err)
	}

	doc.SetGithubCredentials(beego.AppConfig.String("client_id"), beego.AppConfig.String("client_secret"))
}
示例#2
0
func init() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	// Set App version and log level.
	routers.AppVer = "v" + APP_VER

	if beego.AppConfig.String("runmode") == "pro" {
		beego.SetLevel(beego.LevelInfo)

		beego.Info("Go Walker Server", APP_VER)

		os.Mkdir("../log", os.ModePerm)
		fw := beego.NewFileWriter("../log/log", true)
		err := fw.StartLogger()
		if err != nil {
			beego.Critical("NewFileWriter ->", err)
		}
	}

	doc.SetGithubCredentials(utils.Cfg.MustValue("github", "client_id"),
		utils.Cfg.MustValue("github", "client_secret"))
}
示例#3
0
// We have to call a initialize function manully
// because we use `bee bale` to pack static resources
// and we cannot make sure that which init() execute first.
func initialize() {
	// Load configuration, set app version and log level.
	utils.LoadConfig("conf/app.ini")

	// Load locale files.
	langs := strings.Split(utils.Cfg.MustValue("lang", "types"), "|")
	// Skip en-US.
	for i := 1; i < len(langs); i++ {
		err := i18n.SetMessage(langs[i], "conf/locale_"+langs[i]+".ini")
		if err != nil {
			panic("Fail to set message file: " + err.Error())
		}
	}

	// Trim 4th part.
	routers.AppVer = strings.Join(strings.Split(APP_VER, ".")[:3], ".")

	beego.AppName = utils.Cfg.MustValue("beego", "app_name")
	beego.RunMode = utils.Cfg.MustValue("beego", "run_mode")
	beego.HttpPort = utils.Cfg.MustInt("beego", "http_port_"+beego.RunMode)

	routers.IsBeta = utils.Cfg.MustBool("server", "beta")
	routers.IsProMode = beego.RunMode == "prod"
	if routers.IsProMode {
		beego.SetLevel(beego.LevelInfo)
		beego.Info("Product mode enabled")

		os.Mkdir("./log", os.ModePerm)
		beego.BeeLogger.SetLogger("file", `{"filename": "log/log"}`)
	}

	// Initialize data.
	models.InitDb()
	routers.InitRouter()

	doc.SetGithubCredentials(utils.Cfg.MustValue("github", "client_id"),
		utils.Cfg.MustValue("github", "client_secret"))
}