router_check_role.go.template 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. package router
  2. import (
  3. "github.com/gin-gonic/gin"
  4. jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth"
  5. "go-admin/app/{{.PackageName}}/models"
  6. "go-admin/app/{{.PackageName}}/service/dto"
  7. "go-admin/common/actions"
  8. "go-admin/common/middleware"
  9. )
  10. func init() {
  11. routerCheckRole = append(routerCheckRole, register{{.ClassName}}Router)
  12. }
  13. // 需认证的路由代码
  14. func register{{.ClassName}}Router(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
  15. r := v1.Group("/{{.ModuleName}}").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
  16. {
  17. model := &models.{{.ClassName}}{}
  18. r.GET("", actions.PermissionAction(), actions.IndexAction(model, new(dto.{{.ClassName}}Search), func() interface{} {
  19. list := make([]models.{{.ClassName}}, 0)
  20. return &list
  21. }))
  22. r.GET("/:id", actions.PermissionAction(), actions.ViewAction(new(dto.{{.ClassName}}ById), nil))
  23. r.POST("", actions.CreateAction(new(dto.{{.ClassName}}Control)))
  24. r.PUT("/:id", actions.PermissionAction(), actions.UpdateAction(new(dto.{{.ClassName}}Control)))
  25. r.DELETE("", actions.PermissionAction(), actions.DeleteAction(new(dto.{{.ClassName}}ById)))
  26. }
  27. }