-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
49 lines (42 loc) · 1.55 KB
/
main.go
File metadata and controls
49 lines (42 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"strings"
"github.com/astaxie/beego/context"
ms "auto_release/models/mysql"
_ "auto_release/routers"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/plugins/cors"
_ "github.com/go-sql-driver/mysql"
)
var FilterUser = func(ctx *context.Context) {
_, ok := ctx.Input.Session("uid").(string)
ok2 := strings.Contains(ctx.Request.RequestURI, "/login")
if !ok && !ok2 {
ctx.Redirect(302, "/release-stg")
}
}
func init() {
db, _ := ms.InitDb()
db.AutoMigrate(&ms.Env{}, &ms.Host{}, &ms.ServEnv{}, &ms.RouteItem{}, &ms.User{}, &ms.UserConf{})
db.Model(&ms.ServEnv{}).AddUniqueIndex("idx_serv_env", "serv_id", "env_id")
db.Model(&ms.RouteItem{}).AddUniqueIndex("idx_parentid_name", "parent_id", "name")
//a := gormadapter.NewAdapterByDB(db)
//ctl.E = casbin.NewEnforcer("conf/rbac.conf", a)
}
func main() {
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowAllOrigins: true,
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
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,
}))
//beego.InsertFilter("/*", beego.BeforeRouter, FilterUser)
//beego.BConfig.WebConfig.ViewsPath = "dist"
logs.SetLogger("file", `{"filename":"logs/log.log"}`)
logs.EnableFuncCallDepth(true)
logs.Async()
beego.Run()
//e.SavePolicy()
}