forked from IceWhaleTech/CasaOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (63 loc) · 1.63 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
package main
import (
"flag"
"fmt"
"github.com/IceWhaleTech/CasaOS/pkg/config"
"github.com/IceWhaleTech/CasaOS/pkg/sqlite"
loger2 "github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
"github.com/IceWhaleTech/CasaOS/route"
"github.com/IceWhaleTech/CasaOS/service"
"github.com/gin-gonic/gin"
"github.com/robfig/cron"
"gorm.io/gorm"
"net/http"
"time"
)
var sqliteDB *gorm.DB
var swagHandler gin.HandlerFunc
var configFlag = flag.String("c", "", "config address")
func init() {
flag.Parse()
config.InitSetup(*configFlag)
loger2.LogSetup()
sqliteDB = sqlite.GetDb(config.AppInfo.ProjectPath)
//gredis.GetRedisConn(config.RedisInfo),
service.MyService = service.NewService(sqliteDB, loger2.NewOLoger())
}
// @title Oasis API
// @version 1.0.0
// @contact.name lauren.pan
// @contact.url https://www.zimaboard.com
// @contact.email [email protected]
// @description Oasis v1版本api
// @host 192.168.2.114:8089
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization
// @BasePath /v1
func main() {
//model.Setup()
//gredis.Setup()
r := route.InitRouter(swagHandler)
service.SyncTask(sqliteDB)
cron2 := cron.New() //创建一个cron实例
//执行定时任务(每5秒执行一次)
err := cron2.AddFunc("0 0 0 1/1 * *", func() {
//service.UpdataDDNSList(mysqldb)
service.SyncTask(sqliteDB)
})
if err != nil {
fmt.Println(err)
}
//启动/关闭
cron2.Start()
defer cron2.Stop()
s := &http.Server{
Addr: fmt.Sprintf(":%v", config.ServerInfo.HttpPort),
Handler: r,
ReadTimeout: 60 * time.Second,
WriteTimeout: 60 * time.Second,
MaxHeaderBytes: 1 << 20,
}
s.ListenAndServe()
}