迁移
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
const (
|
||||
codeSuccess = 0
|
||||
codeError = 7
|
||||
codePasswordChangeRequired = 10001
|
||||
)
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
func writeResult(c *gin.Context, code int, data any, message string) {
|
||||
c.JSON(http.StatusOK, response{Code: code, Data: data, Msg: message})
|
||||
}
|
||||
|
||||
func ok(c *gin.Context) {
|
||||
writeResult(c, codeSuccess, gin.H{}, "操作成功")
|
||||
}
|
||||
|
||||
func okWithData(c *gin.Context, data any) {
|
||||
writeResult(c, codeSuccess, data, "成功")
|
||||
}
|
||||
|
||||
func fail(c *gin.Context, message string) {
|
||||
writeResult(c, codeError, gin.H{}, message)
|
||||
}
|
||||
|
||||
func noAuth(c *gin.Context, message string) {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, response{
|
||||
Code: codeError,
|
||||
Data: nil,
|
||||
Msg: message,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user