teldrive/main.go

65 lines
1.3 KiB
Go
Raw Normal View History

2023-08-07 03:32:46 +08:00
package main
import (
2023-08-12 19:21:42 +08:00
"time"
2023-08-16 05:53:02 +08:00
"github.com/divyam234/teldrive/cache"
"github.com/divyam234/teldrive/database"
"github.com/divyam234/teldrive/routes"
"github.com/divyam234/teldrive/utils"
2023-08-07 03:32:46 +08:00
2023-08-12 19:21:42 +08:00
"github.com/divyam234/cors"
2023-08-16 20:48:32 +08:00
"github.com/divyam234/teldrive/utils/cron"
2023-08-07 03:32:46 +08:00
"github.com/gin-gonic/gin"
2023-08-16 20:48:32 +08:00
"github.com/go-co-op/gocron"
2023-08-07 03:32:46 +08:00
"github.com/joho/godotenv"
)
func main() {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
godotenv.Load()
2023-08-12 19:21:42 +08:00
utils.InitConfig()
utils.InitializeLogger()
2023-08-07 03:32:46 +08:00
database.InitDB()
cache.CacheInit()
2023-08-12 19:21:42 +08:00
utils.StartBotTgClients()
2023-08-16 20:48:32 +08:00
cron.FilesDeleteJob()
scheduler := gocron.NewScheduler(time.UTC)
scheduler.Every(4).Hours().Do(cron.FilesDeleteJob)
2023-08-12 19:21:42 +08:00
router.Use(cors.New(cors.Config{
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
return true
},
MaxAge: 12 * time.Hour,
}))
2023-08-07 03:32:46 +08:00
router.Use(gin.ErrorLogger())
routes.GetRoutes(router)
2023-08-17 23:32:40 +08:00
ok, _ := utils.PathExists("./sslcerts")
config := utils.GetConfig()
if ok && config.Https {
router.RunTLS(":8080", "./sslcerts/cert.pem", "./sslcerts/key.pem")
} else {
router.Run(":8080")
}
2023-08-16 20:48:32 +08:00
scheduler.StartAsync()
2023-08-07 03:32:46 +08:00
}