forked from tgdrive/teldrive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (46 loc) · 1.38 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
package main
import (
"fmt"
"mime"
"path/filepath"
"time"
"github.com/divyam234/teldrive/database"
"github.com/divyam234/teldrive/routes"
"github.com/divyam234/teldrive/ui"
"github.com/divyam234/teldrive/utils"
"github.com/divyam234/cors"
"github.com/divyam234/teldrive/utils/cron"
"github.com/gin-gonic/gin"
"github.com/go-co-op/gocron"
)
func main() {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
utils.InitConfig()
utils.InitializeLogger()
database.InitDB()
scheduler := gocron.NewScheduler(time.UTC)
scheduler.Every(1).Hour().Do(cron.FilesDeleteJob)
scheduler.StartAsync()
router.Use(cors.New(cors.Config{
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"},
AllowHeaders: []string{"Authorization", "Content-Length", "Content-Type"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
return true
},
MaxAge: 12 * time.Hour,
}))
mime.AddExtensionType(".js", "application/javascript")
router.Use(gin.ErrorLogger())
routes.AddRoutes(router)
ui.AddRoutes(router)
config := utils.GetConfig()
certDir := filepath.Join(config.ExecDir, "sslcerts")
ok, _ := utils.PathExists(certDir)
if ok && config.Https {
router.RunTLS(fmt.Sprintf(":%d", config.Port), filepath.Join(certDir, "cert.pem"), filepath.Join(certDir, "key.pem"))
} else {
router.Run(fmt.Sprintf(":%d", config.Port))
}
}