-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (53 loc) · 1.35 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
package main
import (
"fmt"
"io"
"log"
"os"
"github.com/Pepijn98/kyra/config"
"github.com/Pepijn98/kyra/database"
"github.com/Pepijn98/kyra/utils"
"github.com/joho/godotenv"
)
// Starting template
func main() {
os.MkdirAll("./files", os.ModePerm)
os.MkdirAll("./images", os.ModePerm)
os.MkdirAll("./thumbnails", os.ModePerm)
if err := godotenv.Load(); err != nil {
log.Fatal("Error loading .env file")
}
port := os.Getenv("PORT")
if utils.IsEmptyString(port) {
log.Fatal("PORT is not set in .env file")
}
err := database.Connect()
if err != nil {
log.Fatalf("Error connecting to database: %v", err)
}
db := database.DB
defer db.Close()
if err := db.Ping(); err != nil {
log.Fatalf("Failed to ping: %v", err)
}
logs, err := os.OpenFile("./logs/errors.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0665)
if err != nil {
log.Fatalf("Error opening log file: %v", err)
}
defer logs.Close()
wrt := io.MultiWriter(os.Stdout, logs)
log.SetOutput(wrt)
jwt_secret := os.Getenv("JWT_SECRET")
if utils.IsEmptyString(jwt_secret) {
log.Fatal("JWT_SECRET is not set in .env file")
}
host := os.Getenv("HOST")
if utils.IsEmptyString(host) {
log.Fatal("JWT_SECRET is not set in .env file")
}
config.Init(host, jwt_secret)
// Define the app configuration
app := InitRoutes()
defer app.Shutdown()
app.Listen(fmt.Sprintf(":%s", port))
}