main.go
979 Bytes
package main
import (
"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"
}
_ = dto.Inits()
// 初始化配置
cardholder.Init()
beego.Run()
}