main.go 1.42 KB
package main

import (
	"apigame/configs"
	_ "apigame/routers"
	"apigame/service"
	"apigame/service-common/svconst"
	"apigame/service-common/svlog"
	"apigame/service-common/svmysql"
	"apigame/service-common/svredis"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/logs"
	"github.com/astaxie/beego/plugins/cors"
)

func main() {
	logs.Info("apigame")

	//解决跨域问题
	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowAllOrigins: true,
		//AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowMethods:     []string{"POST"},
		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
		AllowCredentials: true,
	}))

	if beego.BConfig.RunMode == "dev" {
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
	}

	if !Init() {
		return
	}

	beego.Run()
}

func Init() bool {

	svconst.AppName = beego.AppConfig.String("appname")

	svlog.Init()

	svlog.InitAliLog(svconst.AppName)

	if !svredis.Init() {
		return false
	}

	if !svmysql.Init() {
		return false
	}

	//// 初始化数数打点
	//_ = thinkingdata.InitThinkData()
	//
	//_ = config.InitLxLimit()

	if !configs.Init() {
		return false
	}

	service.Init()

	return true
}