-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (43 loc) · 1.34 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 (
"awesomeProject/main/config"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
"log"
_ "awesomeProject/main/docs" //docs api hasil generate swagger
"github.com/gofiber/fiber/v2"
"github.com/swaggo/http-swagger"
"github.com/valyala/fasthttp/fasthttpadaptor"
)
func main() {
config.ConnectDatabase()
config.MigrateDatabase()
app := fiber.New()
app.Use(logger.New())
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
}))
//inject
projectController, err := InitializeProject()
categoryController, err := InitializeCategory()
if err != nil {
log.Fatalf("Error initializing project controller: %v", err)
}
//route ke swagger
app.Get("/swagger/*", func(c *fiber.Ctx) error {
//konversi handler swagger
handler := fasthttpadaptor.NewFastHTTPHandler(httpSwagger.Handler(
httpSwagger.URL("/swagger/doc.json"), //url ke doc.json
))
//Menggunakan handler fasthttp pada Fiber
handler(c.Context()) //Panggil handler fasthttp
return nil
})
//route
app.Get("/project/:id", projectController.GetProjectDetails)
app.Get("/project", projectController.GetAllProject)
app.Post("/project", projectController.AddProject)
app.Get("/category/names", categoryController.ShowAllCategoryNames)
app.Static("/project-images", "./uploads/images")
log.Fatal(app.Listen(":8080"))
}