daShangDao_getErpSendPublis.../utils/response.go
2026-06-15 16:18:50 +08:00

27 lines
665 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
import (
"github.com/gin-gonic/gin"
"net/http"
"time"
)
func JSON(c *gin.Context, httpStatus int, code int, message string, data interface{}) {
c.JSON(httpStatus, ApiResponse{
Code: code,
Message: message,
Data: data,
Timestamp: time.Now(), // 自动填充当前时间
})
}
// Success 成功响应简化版Code=200Message="success"
func Success(c *gin.Context, data any) {
JSON(c, http.StatusOK, CodeSuccess, "success", data)
}
// Error 失败响应(简化版,自动匹配 HTTP 状态码)
func Error(c *gin.Context, httpStatus int, code int, message string) {
JSON(c, httpStatus, code, message, nil)
}