-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (54 loc) · 1.78 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
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/sutantodadang/adopt-me/v1/db"
"github.com/sutantodadang/adopt-me/v1/handler"
"github.com/sutantodadang/adopt-me/v1/middleware"
"github.com/sutantodadang/adopt-me/v1/routes"
"github.com/sutantodadang/adopt-me/v1/services"
"github.com/sutantodadang/adopt-me/v1/utils"
)
func main() {
// di aktifkan kalau berjalan di lokal
// err := godotenv.Load()
// if err != nil {
// log.Fatal("Failed load env", err.Error())
// }
key := os.Getenv("MONGO_URI")
secret := os.Getenv("SECRET_KEY")
port := os.Getenv("PORT")
key_img := os.Getenv("KEY_IMG")
url_img := os.Getenv("IMG_URL")
app := fiber.New()
app.Use(logger.New())
app.Use(cors.New())
Database := db.GetClient(key)
// memanggil service
userService := services.NewServiceUser(Database)
catService := services.NewServiceCat(Database)
galleryService := services.NewServiceGalery(Database)
jwtService := utils.NewJwt(secret)
middleService := middleware.NewAuthMiddleware(secret)
// memanggil handler
userHandler := handler.NewUserHandler(userService, jwtService)
catHandler := handler.NewCatHandler(catService)
galleryHandler := handler.NewGalleryHandler(galleryService, catService, url_img, key_img)
// memanggil route
userRoute := routes.NewUserRoute(userHandler, middleService)
catRoute := routes.NewCatRoute(catHandler, middleService)
galleryRoute := routes.NewGalleryRoute(galleryHandler, middleService)
// set route
userRoute.UserRouter(app)
catRoute.CatRouter(app)
galleryRoute.GalleryRouter(app)
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Welcome To Adopt Me Api")
})
if port == "" {
port = "27017"
}
app.Listen(":" + port)
}