-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
54 lines (41 loc) · 1.4 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
package main
import (
"log"
"net/http"
"os"
"github.com/go-fuego/fuego"
"github.com/rs/cors"
_ "github.com/joho/godotenv/autoload"
controller "github.com/tempfiles-Team/tempfiles-backend/controllers"
"github.com/tempfiles-Team/tempfiles-backend/crontab"
"github.com/tempfiles-Team/tempfiles-backend/database"
"github.com/tempfiles-Team/tempfiles-backend/utils"
)
func main() {
crontab.Crontab()
if err := utils.CheckTmpFolder(); err != nil {
log.Fatalf("tmp folder error: %v", err)
}
if err := database.CreateDBEngine(); err != nil {
log.Fatalf("failed to create db engine: %v", err)
}
// ======================== SERVER ========================
if os.Getenv("BACKEND_PORT") == "" {
os.Setenv("BACKEND_PORT", "5000")
}
port := utils.CheckPortAvailable(os.Getenv("BACKEND_PORT"))
s := fuego.NewServer(
fuego.WithAddr("0.0.0.0:"+port),
fuego.WithCorsMiddleware(cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{http.MethodGet, http.MethodPost, http.MethodDelete},
AllowedHeaders: []string{"Origin", "Content-Type", "Accept", "X-Download-Limit", "X-Time-Limit", "X-Hidden"},
}).Handler),
)
fuego.Get(s, "/", func(c fuego.ContextNoBody) (string, error) {
return "TEMPFILES API WORKING 🚀\nIf you want to use the API, go to '/swagger'", nil
}).Tags("default")
v1wv := fuego.Group(s, "/")
controller.FilesRessources{}.RoutesV1(v1wv)
s.Run()
}