-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (46 loc) · 1.16 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
package main
import (
"github.com/bytixo/TokenGrabber_API/database"
"github.com/bytixo/TokenGrabber_API/user"
"github.com/joho/godotenv"
"github.com/pieterclaerhout/go-log"
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func main() {
godotenv.Load()
log.DebugMode = true
log.DebugSQLMode = true
log.PrintTimestamp = true
log.PrintColors = true
log.TimeFormat = "[2006-01-02 15:04:05.000]"
app := fiber.New()
app.Use(logger.New())
initDatabase()
setupRoutes(app)
port := os.Getenv("PORT")
log.Fatal(app.Listen(port))
}
func setupRoutes(app *fiber.App) {
app.Post("/api/token", user.SingleToken)
app.Get("/api/users", user.GetUsers)
}
func initDatabase() {
var err error
database.DBConn, err = gorm.Open(sqlite.Open("users.db"), &gorm.Config{
PrepareStmt: false,
SkipDefaultTransaction: true,
})
if err != nil {
panic("Failed to connect to database")
}
log.Info("Successfully connected to database")
err = database.DBConn.AutoMigrate(&database.User{})
if err != nil {
log.Error("Couldn't migrate database", err)
}
log.Info("Database Migrated")
}