优化结构

This commit is contained in:
Yvan
2026-08-21 00:28:09 +08:00
parent 361a562f75
commit 13f4589a18
21 changed files with 32 additions and 506 deletions
+11 -22
View File
@@ -1,40 +1,29 @@
package httpx
import (
"net/http"
"github.com/gin-gonic/gin"
shared "kra/pkg/httpx"
)
const (
CodeSuccess = 0
CodeError = 7
CodePasswordChangeRequired = 10001
CodeSuccess = shared.CodeSuccess
CodeError = shared.CodeError
CodePasswordChangeRequired = shared.CodePasswordChangeRequired
)
type Response struct {
Code int `json:"code"`
Data any `json:"data"`
Msg string `json:"msg"`
}
type PageResult struct {
List any `json:"list"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
}
type Response = shared.Response
type PageResult = shared.PageResult
func Write(c *gin.Context, code int, data any, message string) {
c.JSON(http.StatusOK, Response{Code: code, Data: data, Msg: message})
shared.Write(c, code, data, message)
}
func OK(c *gin.Context) { Write(c, CodeSuccess, gin.H{}, "操作成功") }
func OK(c *gin.Context) { shared.OK(c) }
func OKWithData(c *gin.Context, data any) { Write(c, CodeSuccess, data, "成功") }
func OKWithData(c *gin.Context, data any) { shared.OKWithData(c, data) }
func Fail(c *gin.Context, message string) { Write(c, CodeError, gin.H{}, message) }
func Fail(c *gin.Context, message string) { shared.Fail(c, message) }
func NoAuth(c *gin.Context, message string) {
c.AbortWithStatusJSON(http.StatusUnauthorized, Response{Code: CodeError, Data: nil, Msg: message})
shared.NoAuth(c, message)
}