Files

41 lines
1.1 KiB
Go

package router
import (
"context"
"github.com/gogf/gf/v2/errors/gcode"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/controller/app"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/contexts"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/mcache"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/packed/response"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/service"
"github.com/gogf/gf/v2/net/ghttp"
)
func App(ctx context.Context, group *ghttp.RouterGroup) {
group.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(
func(r *ghttp.Request) {
ctx := r.GetCtx()
userId := contexts.GetUserId(ctx)
if userId != 0 && !contexts.IsSuperAdmin(ctx) {
freshCtx, err := mcache.WithFreshUserAccess(ctx, userId)
if err != nil {
response.JsonExit(r, gcode.CodeNotAuthorized.Code(), "权限校验失败,请重试")
return
}
r.SetCtx(freshCtx)
}
r.Middleware.Next()
},
service.Middleware().Auth,
)
group.Bind(
app.NewV1(),
&app.ExecutionLogController{},
&app.AllocateResultController{},
)
})
}