2021-09-26 02:35:02 +00:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
2021-10-15 03:43:41 +00:00
|
|
|
|
"net/http"
|
|
|
|
|
"time"
|
|
|
|
|
|
2021-10-29 10:37:27 +00:00
|
|
|
|
"github.com/IceWhaleTech/CasaOS/pkg/cache"
|
2021-09-27 06:17:36 +00:00
|
|
|
|
"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"
|
2021-10-29 10:37:27 +00:00
|
|
|
|
|
2021-09-26 02:35:02 +00:00
|
|
|
|
"github.com/robfig/cron"
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var sqliteDB *gorm.DB
|
|
|
|
|
|
|
|
|
|
var configFlag = flag.String("c", "", "config address")
|
|
|
|
|
|
2021-10-22 08:49:09 +00:00
|
|
|
|
var showUserInfo = flag.Bool("show-user-info", false, "show user info")
|
|
|
|
|
|
2021-09-26 02:35:02 +00:00
|
|
|
|
func init() {
|
|
|
|
|
flag.Parse()
|
|
|
|
|
config.InitSetup(*configFlag)
|
2021-10-15 03:43:41 +00:00
|
|
|
|
config.UpdateSetup()
|
2021-09-26 02:35:02 +00:00
|
|
|
|
loger2.LogSetup()
|
|
|
|
|
sqliteDB = sqlite.GetDb(config.AppInfo.ProjectPath)
|
|
|
|
|
//gredis.GetRedisConn(config.RedisInfo),
|
|
|
|
|
service.MyService = service.NewService(sqliteDB, loger2.NewOLoger())
|
2021-10-29 10:37:27 +00:00
|
|
|
|
service.Cache = cache.Init()
|
2021-11-09 10:57:50 +00:00
|
|
|
|
route.InitFunction()
|
2021-09-26 02:35:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-22 08:49:09 +00:00
|
|
|
|
// @title casaOS API
|
2021-09-26 02:35:02 +00:00
|
|
|
|
// @version 1.0.0
|
|
|
|
|
// @contact.name lauren.pan
|
|
|
|
|
// @contact.url https://www.zimaboard.com
|
|
|
|
|
// @contact.email lauren.pan@icewhale.org
|
2021-10-22 08:49:09 +00:00
|
|
|
|
// @description casaOS v1版本api
|
|
|
|
|
// @host 192.168.2.217:8089
|
2021-09-26 02:35:02 +00:00
|
|
|
|
// @securityDefinitions.apikey ApiKeyAuth
|
|
|
|
|
// @in header
|
|
|
|
|
// @name Authorization
|
|
|
|
|
// @BasePath /v1
|
|
|
|
|
func main() {
|
2021-10-22 08:49:09 +00:00
|
|
|
|
if *showUserInfo {
|
|
|
|
|
fmt.Println("CasaOS User Info")
|
|
|
|
|
fmt.Println("UserName:" + config.UserInfo.UserName)
|
|
|
|
|
fmt.Println("Password:" + config.UserInfo.PWD)
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-09-26 02:35:02 +00:00
|
|
|
|
//model.Setup()
|
|
|
|
|
//gredis.Setup()
|
2021-10-22 08:49:09 +00:00
|
|
|
|
r := route.InitRouter()
|
2021-09-29 11:49:34 +00:00
|
|
|
|
//service.SyncTask(sqliteDB)
|
2021-09-26 02:35:02 +00:00
|
|
|
|
cron2 := cron.New() //创建一个cron实例
|
|
|
|
|
//执行定时任务(每5秒执行一次)
|
|
|
|
|
err := cron2.AddFunc("0 0 0 1/1 * *", func() {
|
|
|
|
|
//service.UpdataDDNSList(mysqldb)
|
2021-09-29 11:49:34 +00:00
|
|
|
|
//service.SyncTask(sqliteDB)
|
2021-09-26 02:35:02 +00:00
|
|
|
|
})
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
}
|