第 1 阶段:用户与认证, mock登陆ok

This commit is contained in:
yml
2026-05-22 15:21:36 +08:00
parent 8e7f1f17f0
commit 9a79603e10
21 changed files with 780 additions and 4 deletions
+48
View File
@@ -0,0 +1,48 @@
package response
import (
"net/http"
"github.com/gin-gonic/gin"
)
type Body struct {
Code string `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
func OK(c *gin.Context, data any) {
c.JSON(http.StatusOK, Body{
Code: "ok",
Message: "ok",
Data: data,
})
}
func Created(c *gin.Context, data any) {
c.JSON(http.StatusCreated, Body{
Code: "ok",
Message: "created",
Data: data,
})
}
func Error(c *gin.Context, status int, code, message string) {
c.JSON(status, Body{
Code: code,
Message: message,
})
}
func BadRequest(c *gin.Context, message string) {
Error(c, http.StatusBadRequest, "bad_request", message)
}
func Unauthorized(c *gin.Context, message string) {
Error(c, http.StatusUnauthorized, "unauthorized", message)
}
func ServiceUnavailable(c *gin.Context, message string) {
Error(c, http.StatusServiceUnavailable, "service_unavailable", message)
}