-
Notifications
You must be signed in to change notification settings - Fork 42
/
main.go
46 lines (40 loc) · 1.08 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
package main
import (
"github.com/Qsnh/goa/middlewares"
"github.com/Qsnh/goa/models"
_ "github.com/Qsnh/goa/routers"
"github.com/Qsnh/goa/tasks"
"github.com/Qsnh/goa/utils"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/toolbox"
_ "github.com/go-sql-driver/mysql"
"github.com/joho/godotenv"
"log"
"os"
"path/filepath"
)
func main() {
err := godotenv.Load(utils.Pwd() string(filepath.Separator) ".env")
if err != nil {
log.Fatal("can't find .env file")
return
}
models.Init()
// 中间件注册
middlewares.LoginCheck()
middlewares.CorsHandler()
middlewares.BackendLoginCheck()
// 模板函数注册
beego.AddFuncMap("urlquery", utils.Url)
beego.AddFuncMap("timeforhumnas", utils.TimeDiffForHumans)
beego.AddFuncMap("chls", utils.ComputedHandlerSeconds)
// 定时任务
backupTask := toolbox.NewTask("backup_task", "0 0 05 * * *", tasks.WebBackupTask)
toolbox.AddTask("backup_task", backupTask)
toolbox.StartTask()
defer toolbox.StopTask()
// 运行
beego.Run(":" os.Getenv("APP_PORT"))
logs.SetLogger("console")
}