main.go
1.17 KB
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
package main
import (
"log"
"ui.ac.id/dtd/go-webserver-boilerplate/internal/domain"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/healthcheck"
"github.com/gofiber/fiber/v3/middleware/logger"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"ui.ac.id/dtd/go-webserver-boilerplate/internal/handler"
"ui.ac.id/dtd/go-webserver-boilerplate/internal/repository/postgresql"
"ui.ac.id/dtd/go-webserver-boilerplate/internal/service"
)
func main() {
config := domain.InitConfig()
db, err := gorm.Open(postgres.Open(config.DatabaseUrl), &gorm.Config{})
if err != nil {
log.Fatal(err)
}
userRepository := postgresql.NewPostgresUserRepository(db)
userService := service.NewUserService(userRepository)
userHandler := handler.NewUserHandler(userService)
app := fiber.New(fiber.Config{
ErrorHandler: handler.ErrorHandler,
})
app.Use(logger.New())
app.Get("/", healthcheck.NewHealthChecker())
//api group
api := app.Group("/api")
//v1 api
v1 := api.Group("/v1")
//user group
user := v1.Group("/user")
user.Get("/:id", userHandler.GetUserDetail)
user.Get("/", userHandler.GetUserList)
err = app.Listen(":" + config.Port)
if err != nil {
return
}
}