Compare commits
2 Commits
54e2d88db3
...
c6fe82c7e6
Author | SHA1 | Date | |
---|---|---|---|
|
c6fe82c7e6 | ||
|
0dd0d5db67 |
@ -22,10 +22,12 @@ import (
|
||||
)
|
||||
|
||||
func InitSimulationRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
|
||||
authed := api.Group("/v1/simulation").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
|
||||
authed.POST("/createByProject", createByProjectId)
|
||||
authed.POST("/destroy/:id", destroy)
|
||||
authed.GET("/list", findAllSimulations)
|
||||
|
||||
authed.POST("/check/data", checkSimMapData)
|
||||
authed.POST("/train/add", addTrain)
|
||||
authed.POST("/train/config", configTrain)
|
||||
|
@ -21,6 +21,7 @@ func InitUserRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware)
|
||||
authed := api.Group("/v1/user").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
|
||||
authed.GET("/paging", pageQueryUser)
|
||||
authed.GET("/current", findUserInfo)
|
||||
|
||||
}
|
||||
|
||||
// 用户注册
|
||||
|
@ -2,6 +2,7 @@ package middleware
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
@ -36,12 +37,16 @@ func permissionMiddleware() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
path, method := c.Request.URL.Path, c.Request.Method
|
||||
if method == http.MethodGet {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
if validateUserPath(path, method, userAuth.AuthPaths) { // 用户有权限
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
slog.Error("无权限操作请求路径", "path", path, "method", method)
|
||||
panic(sys_error.New("权限不足"))
|
||||
panic(sys_error.NewCode("权限不足", 403))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,11 @@ func initServer() *gin.Engine {
|
||||
}
|
||||
}
|
||||
c.Error(be)
|
||||
c.JSON(http.StatusInternalServerError, &dto.ErrorDto{
|
||||
statusCode := http.StatusInternalServerError
|
||||
if be.ErrorCode > 0 {
|
||||
statusCode = http.StatusForbidden
|
||||
}
|
||||
c.JSON(statusCode, &dto.ErrorDto{
|
||||
Tip: be.UserMsg,
|
||||
Message: be.Error(),
|
||||
})
|
||||
|
@ -11,6 +11,7 @@ type BusinessError struct {
|
||||
UserMsg string
|
||||
// 错误信息传递(用于开发回溯定位,不给用户展示)
|
||||
Errors []string
|
||||
ErrorCode int
|
||||
}
|
||||
|
||||
// 新建业务错误
|
||||
@ -34,7 +35,26 @@ func New(userMsg string, errs ...error) *BusinessError {
|
||||
// Errors: convert(errs),
|
||||
}
|
||||
}
|
||||
|
||||
func NewCode(userMsg string, errCode int, errs ...error) *BusinessError {
|
||||
if len(errs) == 1 {
|
||||
be, ok := errs[0].(*BusinessError)
|
||||
if ok {
|
||||
be.prependUserMsg(userMsg)
|
||||
return be
|
||||
} else {
|
||||
return &BusinessError{
|
||||
UserMsg: userMsg,
|
||||
ErrorCode: errCode,
|
||||
Errors: []string{errs[0].Error()},
|
||||
}
|
||||
}
|
||||
}
|
||||
return &BusinessError{
|
||||
UserMsg: userMsg,
|
||||
ErrorCode: errCode,
|
||||
// Errors: convert(errs),
|
||||
}
|
||||
}
|
||||
func IsBusinessError(err error) bool {
|
||||
_, ok := err.(*BusinessError)
|
||||
return ok
|
||||
|
Loading…
Reference in New Issue
Block a user