-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (49 loc) · 1.24 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 (
"fmt"
"log"
"os"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/shubhamku044/restaurant-management-system/database"
"github.com/shubhamku044/restaurant-management-system/middleware"
"github.com/shubhamku044/restaurant-management-system/routes"
"go.mongodb.org/mongo-driver/mongo"
)
var foodCollection *mongo.Collection = database.OpenCollection(database.Client, "food")
func main() {
err := godotenv.Load(".env")
if err != nil {
log.Fatalf("Error loading .env file")
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
router := gin.New()
if os.Getenv("ENV") == "production" {
gin.SetMode(gin.ReleaseMode)
router.Use(gin.Recovery())
} else {
router.Use(gin.Logger())
}
router.GET("/health", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "Server is up and running on port " + port,
})
})
routes.UserRoutes(router)
router.Use(middleware.Authentication())
routes.FoodRoutes(router)
routes.OrderRoutes(router)
routes.OrderItemRoutes(router)
routes.MenuRoutes(router)
routes.InvoiceRoutes(router)
routes.TableRoutes(router)
err = router.Run(":" + port)
if err != nil {
fmt.Println("Error starting server: ", err)
os.Exit(1)
}
fmt.Println("Hello, World!")
}