-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (40 loc) · 1.3 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
// ⚡️ Fiber is an Express inspired web framework written in Go with ☕️
// 🤖 Github Repository: https://github.com/gofiber/fiber
// 📌 API Documentation: https://docs.gofiber.io
package main
import (
"fmt"
"learn-go-fiber/helper"
authModule "learn-go-fiber/modules/auth"
todoModule "learn-go-fiber/modules/todo"
userModule "learn-go-fiber/modules/user"
"log"
"github.com/gofiber/fiber/v2"
fiberLogger "github.com/gofiber/fiber/v2/middleware/logger"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
func main() {
fmt.Println("Starting server...")
dsn := "host=localhost user=postgres password=password dbname=go-fiber port=5433 sslmode=disable TimeZone=Asia/Jakarta"
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
Logger: logger.Default.LogMode(logger.Info),
})
if err != nil {
log.Fatal(err.Error())
}
db.AutoMigrate(&userModule.User{}, &todoModule.Todo{})
authServer := authModule.NewServer(db)
todoServer := todoModule.NewServer(db)
app := fiber.New()
app.Use(fiberLogger.New())
authServer.MountRoutes(app)
todoServer.MountRoutes(app)
// 404 Handler
app.Use(func(c *fiber.Ctx) error {
response := helper.APIResponse("Not found", fiber.StatusNotFound, false, nil)
return c.Status(response.Meta.Code).JSON(response)
})
log.Fatal(app.Listen(":3000"))
}