main.go 1.13 KB
package main

import (
	"apigame/common/zconst"
	"apigame/common/zlog"
	"apigame/dto"
	_ "apigame/routers"
	"apigame/service/cardholder"
	"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"
	}

	Init()

	beego.Run()
}

func Init() {

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

	zlog.Init()

	_ = dto.Inits()

	zlog.InitAliLog(zconst.AppName)

	// 初始化配置
	cardholder.Init()
}