feat 网关鉴权

This commit is contained in:
2025-12-22 18:04:36 +08:00
parent 69cc960fe5
commit 670140e7d3
68 changed files with 1424 additions and 492 deletions

View File

@@ -9,6 +9,7 @@ import (
var (
OK = NewCode(0, "OK")
Failed = NewCode(1, "Failed")
TokenInvalid = NewCode(2, "Token无效")
ParamError = NewCode(1001, "参数错误")
NameEmpty = NewCode(1002, "名称不能为空")
NameDuplicate = NewCode(1003, "名称或编号不能重复")

View File

@@ -1,5 +1,10 @@
package http_resp
import (
"github.com/gin-gonic/gin"
"net/http"
)
type RespJsonData struct {
Code int `json:"code"`
Msg string `json:"msg"`
@@ -14,9 +19,29 @@ func Success(data interface{}) *RespJsonData {
}
}
func Error(code int, message string) *RespJsonData {
func Error(code *Code) *RespJsonData {
return &RespJsonData{
Code: code,
Msg: message,
Code: code.Code(),
Msg: code.Error(),
}
}
func JsonOK(c *gin.Context, data *RespJsonData) {
c.JSON(http.StatusOK, data)
}
func JsonBadRequest(c *gin.Context) {
c.JSON(http.StatusBadRequest, Error(ParamError))
}
func JsonMethodNotAllowed(c *gin.Context) {
c.JSON(http.StatusMethodNotAllowed, Error(NewCode(Failed.Code(), "Method Not Allowed")))
}
func JsonNotFound(c *gin.Context) {
c.JSON(http.StatusNotFound, Error(NewCode(Failed.Code(), "Endpoint Not Found")))
}
func AbortUnauthorized(c *gin.Context) {
c.AbortWithStatusJSON(http.StatusUnauthorized, Error(NewCode(Failed.Code(), "Invalid Authorization")))
}