30 lines
706 B
Go
30 lines
706 B
Go
package adminhandler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// ApiResponse matches Java com.aliyun.control.dto.ApiResponse for popadmin.js.
|
|
type ApiResponse struct {
|
|
Success bool `json:"success"`
|
|
Message string `json:"message"`
|
|
Data any `json:"data"`
|
|
}
|
|
|
|
func OK(c *gin.Context, data any) {
|
|
c.JSON(http.StatusOK, ApiResponse{Success: true, Message: "ok", Data: data})
|
|
}
|
|
|
|
func OKMsg(c *gin.Context, msg string, data any) {
|
|
c.JSON(http.StatusOK, ApiResponse{Success: true, Message: msg, Data: data})
|
|
}
|
|
|
|
func Fail(c *gin.Context, status int, msg string) {
|
|
if status <= 0 {
|
|
status = http.StatusBadRequest
|
|
}
|
|
c.JSON(status, ApiResponse{Success: false, Message: msg, Data: nil})
|
|
}
|