forked from xiaowas/go-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·51 lines (42 loc) · 1.26 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
package main
import (
_ "go-blog/routers"
db "go-blog/service/databsae"
"go-blog/utils"
"go-blog/utils/sitemap"
"github.com/astaxie/beego"
"github.com/astaxie/beego/config"
"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
"github.com/robfig/cron/v3"
"github.com/sirupsen/logrus"
)
func init() {
conf, err := config.NewConfig("ini", "conf/app.conf")
if err != nil {
logrus.Fatalf(err.Error())
}
database, _ := db.NewDataBase(conf.String("db::dbType"))
orm.RegisterDriver(database.GetDriverName(), database.GetDriver())
orm.RegisterDataBase(database.GetAliasName(), database.GetDriverName(), database.GetStr())
beego.AddFuncMap("IndexForOne", utils.IndexForOne)
beego.AddFuncMap("IndexAddOne", utils.IndexAddOne)
beego.AddFuncMap("IndexDecrOne", utils.IndexDecrOne)
beego.AddFuncMap("StringReplace", utils.StringReplace)
beego.AddFuncMap("TimeStampToTime", utils.TimeStampToTime)
// 每天0点定时更新站点地图
go func() {
c := cron.New()
//*/1 0 * * *
// 0 0 * * *
c.AddFunc("*/1 * * * *", func() {
sitemap.Sitemap("./", conf.String("url"))
})
c.Start()
}()
}
func main() {
//bee generate appcode -tables="cron" -driver=mysql -conn="root:root@tcp(127.0.0.1:3306)/blog" -level=3
beego.Run()
}