This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.go
47 lines (39 loc) · 1.37 KB
/
routes.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
package routes
// routes package deals with router configuration.
// Currently, it specifically targets gin-gonic router.
// It has methods concerning ports, API version, endpoints, etc.
import (
"log"
"os"
"github.com/JammUtkarsh/cshare-server/controller"
"github.com/JammUtkarsh/cshare-server/middleware"
"github.com/gin-gonic/gin"
)
// SetUpRouter setting up the router Engine and returns the router.
func SetUpRouter() *gin.Engine {
router := gin.Default()
return router
}
// Routes defines router configuration like port and version.
var Routes = func() {
router := SetUpRouter()
basePath := router.Group("/v1")
RegisterUserRoutes(basePath)
log.Fatalln(router.Run(":" + os.Getenv("SERVER_PORT")))
router.GET("/", controller.HomepageHandler)
}
// RegisterUserRoutes defines endpoints of the server.
func RegisterUserRoutes(rg *gin.RouterGroup) {
userRoute := rg.Group("/users")
userRoute.POST("/signup", controller.POSTCreateUser)
userRoute.POST("/login", controller.POSTLogin)
clipRoute := rg.Group("/clip")
// securing user routes using a Auth() function in middleware.
secured := clipRoute.Group("/secured").Use(middleware.Auth())
{
secured.POST("/:username", controller.POSTClipData)
secured.GET("/:username/:clip_id", controller.GETClipData)
secured.GET("/:username", controller.GETAllClipData)
secured.DELETE("/:username", controller.DELETEAllClipData)
}
}