-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added gin to the application, still need to figure why the authenticator isn't working Referred issue: #30
- Loading branch information
1 parent
55ae3bc
commit f353c0f
Showing
11 changed files
with
289 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"gorm.io/gorm" | ||
"rpl-service/controllers/course" | ||
"rpl-service/models" | ||
"rpl-service/platform/middleware" | ||
) | ||
|
||
func InitializeRoutes(router *gin.Engine, db *gorm.DB) { | ||
for _, endpoint := range course.Endpoints { | ||
mapToGinRoute(router, endpoint, db) | ||
} | ||
} | ||
|
||
func mapToGinRoute(router *gin.Engine, endpoint models.Endpoint, db *gorm.DB) { | ||
methods := map[string]func(string, ...gin.HandlerFunc) gin.IRoutes{ | ||
"GET": router.GET, | ||
"POST": router.POST, | ||
"PUT": router.PUT, | ||
"DELETE": router.DELETE, | ||
} | ||
|
||
if endpoint.IsProtected { | ||
methods[endpoint.Method](endpoint.Path, middleware.IsAuthenticated, func(ctx *gin.Context) { | ||
endpoint.HandlerFunction(ctx.Writer, ctx.Request, db) | ||
}) | ||
} else { | ||
methods[endpoint.Method](endpoint.Path, func(ctx *gin.Context) { | ||
endpoint.HandlerFunction(ctx.Writer, ctx.Request, db) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.