1. 调整目录结构

2. 实现user_controller
This commit is contained in:
2025-09-11 23:48:06 +08:00
parent 1aab2e850a
commit 196e63f40d
16 changed files with 298 additions and 21 deletions

View File

@@ -0,0 +1,30 @@
package controller
import (
"net/http"
"github.com/gin-gonic/gin"
)
// Response 定义统一的API响应结构体
type Response struct {
Code int `json:"code"` // 业务状态码
Message string `json:"message"` // 提示信息
Data interface{} `json:"data"` // 业务数据
}
// SendResponse 发送统一格式的JSON响应
// httpStatus 参数现在将几乎总是 http.StatusOK业务状态码通过 Response.Code 传递
func SendResponse(ctx *gin.Context, code int, message string, data interface{}) {
ctx.JSON(http.StatusOK, Response{
Code: code,
Message: message,
Data: data,
})
}
// SendErrorResponse 发送统一格式的错误响应
// 错误响应通常不包含业务数据,因此 data 参数固定为 nil
func SendErrorResponse(ctx *gin.Context, code int, message string) {
SendResponse(ctx, code, message, nil)
}