-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
80 lines (64 loc) · 2.16 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
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/kaizerpwn/homelab-backend/controllers"
"github.com/kaizerpwn/homelab-backend/initializers"
"github.com/kaizerpwn/homelab-backend/utils"
swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
_ "github.com/kaizerpwn/homelab-backend/docs"
)
func init() {
initializers.LoadEnvVariables()
initializers.ConnectToDB()
}
func main() {
r := gin.Default()
// >> 8 MB Maximum upload file size
r.MaxMultipartMemory = 8 << 20
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://localhost:3000"},
AllowMethods: []string{"PUT", "PATCH", "GET", "DELETE", "POST"},
AllowHeaders: []string{"Origin", "Content-Type"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
return origin == "http://localhost:3000"
},
MaxAge: 12 * time.Hour,
}))
v1 := r.Group("/api")
users := v1.Group("/users")
{
users.POST("/register", controllers.Register)
users.POST("/login", controllers.Login)
users.GET("/:id", utils.VerifyToken, controllers.GetUserByID)
users.GET("/", utils.VerifyToken, controllers.GetAllUsers)
}
houses := v1.Group("/houses")
{
houses.GET("/:id", utils.VerifyToken, controllers.GetHouseById)
houses.POST("/", utils.VerifyToken, controllers.CreateHouse)
}
rooms := v1.Group("/rooms")
{
rooms.GET("/", utils.VerifyToken, controllers.GetAllRooms)
rooms.GET("/:id", utils.VerifyToken, controllers.GetAllRoomsByID)
}
devices := v1.Group("/devices")
{
devices.GET("/", utils.VerifyToken, controllers.GetAllDevices)
devices.GET("/:id", utils.VerifyToken, controllers.GetDeviceById)
}
analytics := v1.Group("/analytics")
{
analytics.GET("/houses", utils.VerifyToken, controllers.GetNumberOfAllHouses)
analytics.GET("/rooms", utils.VerifyToken, controllers.GetNumberOfAllRooms)
analytics.GET("/devices", utils.VerifyToken, controllers.GetNumberOfAllDevices)
analytics.GET("/activedevices", utils.VerifyToken, controllers.GetNumberOfActiveDevices)
}
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
r.Run()
}