-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
36 lines (28 loc) · 785 Bytes
/
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
package main
import (
"fmt"
"go-todolist/config"
"go-todolist/controller"
"go-todolist/repository"
"go-todolist/service"
"github.com/gofiber/fiber/v2"
)
func main() {
port := fmt.Sprintf(":%s", config.EnvConfig("PORT"))
database := config.ConnectDB()
todoRepository := repository.NewTodoRepository(database)
todoService := service.NewTodoService(&todoRepository)
todoController := controller.NewTodoController(&todoService)
app := fiber.New()
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello World")
})
app.Get("/todos", todoController.GetAll)
app.Post("/todos", todoController.Create)
app.Put("/todos/:id", todoController.Update)
app.Delete("/todos/:id", todoController.Delete)
err := app.Listen(port)
if err != nil {
panic(err)
}
}