54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package response
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"psi/constant"
|
|
)
|
|
|
|
type Response struct {
|
|
Code int `json:"code"`
|
|
Data interface{} `json:"data"`
|
|
Msg string `json:"msg"`
|
|
}
|
|
|
|
// ExternalAPIResponse 外部接口通用响应结构
|
|
type ExternalAPIResponse struct {
|
|
Code string `json:"code"`
|
|
Msg string `json:"msg"`
|
|
Data interface{} `json:"data"`
|
|
}
|
|
|
|
func Result(code int, data interface{}, msg string, c *gin.Context) {
|
|
c.JSON(http.StatusOK, Response{
|
|
code,
|
|
data,
|
|
msg,
|
|
})
|
|
}
|
|
|
|
func OkWithMessage(message string, c *gin.Context) {
|
|
Result(constant.SUCCESS, map[string]interface{}{}, message, c)
|
|
}
|
|
|
|
func OkWithDetailed(data interface{}, message string, c *gin.Context) {
|
|
Result(constant.SUCCESS, data, message, c)
|
|
}
|
|
|
|
func FailWithMessage(message string, c *gin.Context) {
|
|
Result(constant.ERROR, map[string]interface{}{}, message, c)
|
|
}
|
|
|
|
func FailWithValidateMessage(message string, c *gin.Context) {
|
|
Result(constant.VALIDATE, map[string]interface{}{}, message, c)
|
|
}
|
|
|
|
func NoAuth(message string, c *gin.Context) {
|
|
c.JSON(http.StatusUnauthorized, Response{
|
|
constant.OAUTH,
|
|
nil,
|
|
message,
|
|
})
|
|
}
|