This repository has been archived by the owner on Oct 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
124 lines (110 loc) · 2.78 KB
/
main.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package main
import (
"io/ioutil"
"regexp"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
"github.com/astaxie/beego/logs"
_ "github.com/jinzhu/gorm/dialects/mysql"
"github.com/jungju/aha/admin"
"github.com/jungju/aha/envs"
"github.com/jungju/aha/models"
_ "github.com/jungju/aha/routers"
"github.com/jungju/gorm_manager"
"github.com/jungju/qor_admin_auth"
)
var (
dbreCreate = false
dbLog = false
dbm *gorm_manager.DBManager = nil
)
func main() {
envs.InitEnvs()
beego.Debug("환경 시작", envs.ProdEnv)
if envs.ProdEnv != envs.RealProdEnv {
beego.SetLevel(beego.LevelDebug)
dbreCreate = false
dbLog = true
if envs.ProdEnv == envs.DevProdEnv {
dbreCreate = true
}
} else {
beego.SetLevel(beego.LevelInformational)
}
setDB()
setQOR()
setRouter()
logs.Info("Start App...")
beego.Run()
}
func setRouter() {
//Swagger 설정
if beego.BConfig.RunMode == "dev" {
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
}
//기본 Router 설정
beego.InsertFilter("*", beego.BeforeRouter, func(ctx *context.Context) {
var validAPIURL = regexp.MustCompile(`^/v1/*`)
if validAPIURL.Match([]byte(ctx.Input.URL())) {
beego.Debug("API")
return
}
validAPIURL = regexp.MustCompile(`^/editor/*`)
if validAPIURL.Match([]byte(ctx.Input.URL())) {
beego.Debug("EDITOR")
c, err := ioutil.ReadFile("web/editor/dist/index.html")
if err != nil {
logs.Error(err)
}
ctx.WriteString(string(c))
return
}
validAPIURL = regexp.MustCompile(`^/*`)
if validAPIURL.Match([]byte(ctx.Input.URL())) {
beego.Debug("WWW")
c, err := ioutil.ReadFile("web/www/dist/index.html")
if err != nil {
logs.Error(err)
}
ctx.WriteString(string(c))
return
}
})
//beego.SetStaticPath("/editor/dist", "web/editor/dist")
beego.SetStaticPath("/editor/assets", "web/editor/dist/assets")
beego.SetStaticPath("/assets", "web/www/dist/assets")
}
func setDB() {
var err error
dbm, err = gorm_manager.New(&gorm_manager.DBConfig{
DBType: "mysql",
DBHost: envs.DBHost,
DBPort: envs.DBPort,
DBName: envs.DBName,
DBUser: envs.DBUser,
DBPass: envs.DBPass,
AutoCreateDatabase: true,
RecreateDatabase: dbreCreate,
OnLog: dbLog,
})
if err != nil {
panic(err)
}
if err := models.Initzation(dbm.GetDB()); err != nil {
panic(err)
}
}
func setQOR() {
if mQorAdmin, err := qor_admin_auth.New(&qor_admin_auth.QorAdminConfig{
AdminURL: "admin",
DB: dbm.GetDB(),
AdminUserModel: &models.Admin{},
}); err == nil {
if err := admin.SetAdmin(mQorAdmin, dbm.GetDB()); err != nil {
panic(err)
}
} else {
panic(err)
}
}