-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (37 loc) · 1.23 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
package main
import (
"fmt"
"log"
"os"
"github.com/its-ayush-07/ecommerce-golang/controllers"
"github.com/its-ayush-07/ecommerce-golang/database"
"github.com/its-ayush-07/ecommerce-golang/middleware"
"github.com/its-ayush-07/ecommerce-golang/routes"
"github.com/joho/godotenv"
"github.com/gin-gonic/gin"
)
func main() {
if err := godotenv.Load(); err != nil {
fmt.Println("Error loading .env file:", err)
return
}
port := os.Getenv("PORT")
if port == "" {
port = "8000"
}
app := controllers.NewApplication(database.ProductData(database.Client, "Products"), database.UserData(database.Client, "Users"))
router := gin.New()
router.Use(gin.Logger())
routes.UserRoutes(router)
router.Use(middleware.Authentication())
router.GET("/addtocart", app.AddToCart())
router.GET("/removeitem", app.RemoveItem())
router.GET("/listcart", controllers.GetItemFromCart())
router.POST("/addaddress", controllers.AddAddress())
router.PUT("/edithomeaddress", controllers.EditHomeAddress())
router.PUT("/editworkaddress", controllers.EditWorkAddress())
router.GET("/deleteaddresses", controllers.DeleteAddress())
router.GET("/cartcheckout", app.BuyFromCart())
router.GET("/instantbuy", app.InstantBuy())
log.Fatal(router.Run(":" + port))
}