refactor: split backend transport and domain modules
This commit is contained in:
+11
-32
@@ -1,50 +1,29 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"kra/internal/server/httpx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
const (
|
||||
codeSuccess = 0
|
||||
codeError = 7
|
||||
codePasswordChangeRequired = 10001
|
||||
codeSuccess = httpx.CodeSuccess
|
||||
codeError = httpx.CodeError
|
||||
codePasswordChangeRequired = httpx.CodePasswordChangeRequired
|
||||
)
|
||||
|
||||
type response struct {
|
||||
Code int `json:"code"`
|
||||
Data any `json:"data"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
type response = httpx.Response
|
||||
|
||||
type pageResult struct {
|
||||
List any `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"pageSize"`
|
||||
}
|
||||
type pageResult = httpx.PageResult
|
||||
|
||||
func writeResult(c *gin.Context, code int, data any, message string) {
|
||||
c.JSON(http.StatusOK, response{Code: code, Data: data, Msg: message})
|
||||
httpx.Write(c, code, data, message)
|
||||
}
|
||||
|
||||
func ok(c *gin.Context) {
|
||||
writeResult(c, codeSuccess, gin.H{}, "操作成功")
|
||||
}
|
||||
func ok(c *gin.Context) { httpx.OK(c) }
|
||||
|
||||
func okWithData(c *gin.Context, data any) {
|
||||
writeResult(c, codeSuccess, data, "成功")
|
||||
}
|
||||
func okWithData(c *gin.Context, data any) { httpx.OKWithData(c, data) }
|
||||
|
||||
func fail(c *gin.Context, message string) {
|
||||
writeResult(c, codeError, gin.H{}, message)
|
||||
}
|
||||
func fail(c *gin.Context, message string) { httpx.Fail(c, message) }
|
||||
|
||||
func noAuth(c *gin.Context, message string) {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, response{
|
||||
Code: codeError,
|
||||
Data: nil,
|
||||
Msg: message,
|
||||
})
|
||||
}
|
||||
func noAuth(c *gin.Context, message string) { httpx.NoAuth(c, message) }
|
||||
|
||||
Reference in New Issue
Block a user