forked from go-ignite/ignite-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (52 loc) · 1.2 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
package main
import (
"flag"
"fmt"
"os"
"github.com/gin-gonic/gin"
"github.com/go-ignite/ignite-admin/controllers"
"github.com/go-ignite/ignite-admin/jobs"
utility "github.com/go-ignite/ignite-admin/utils"
"github.com/go-ignite/ignite/utils"
"github.com/go-xorm/xorm"
"github.com/robfig/cron"
)
var (
confPath = flag.String("c", "./conf/config.toml", "config file")
versionFlag = flag.Bool("v", false, "version")
version = "unknown"
)
func main() {
flag.Parse()
if *versionFlag {
fmt.Println(version)
return
}
utility.InitConf(*confPath)
db := utils.InitDB(utility.DB_Driver, utility.DB_Connect)
// For normal mode
if len(os.Args) == 1 {
go initRouter(db)
go initJob(db)
select {}
} else if os.Args[1] == "recover" {
jobs.RecoverTask(db)
}
}
func initRouter(db *xorm.Engine) {
r := gin.Default()
r.Static("/static", "./static")
r.LoadHTMLGlob("static/*.html")
mainRouter := &controllers.MainRouter{}
mainRouter.Initialize(r, db)
}
func initJob(db *xorm.Engine) {
jobs.SetDB(db)
c := cron.New()
cj := &jobs.CronJob{}
c.AddFunc("0 */5 * * * *", cj.InstantStats)
c.AddFunc("0 0 0 * * *", cj.DailyStats)
c.AddFunc("0 0 0 1 * *", cj.MonthlyStats)
c.Start()
select {}
}