28 lines
627 B
Go
28 lines
627 B
Go
package resp
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Body struct {
|
|
Code int `json:"code"`
|
|
Message string `json:"message"`
|
|
Data interface{} `json:"data,omitempty"`
|
|
Meta interface{} `json:"meta,omitempty"`
|
|
}
|
|
|
|
func OK(c *gin.Context, data interface{}) {
|
|
c.JSON(http.StatusOK, Body{Code: 0, Message: "ok", Data: data})
|
|
}
|
|
|
|
func OKMeta(c *gin.Context, data interface{}, meta interface{}) {
|
|
c.JSON(http.StatusOK, Body{Code: 0, Message: "ok", Data: data, Meta: meta})
|
|
}
|
|
|
|
func Fail(c *gin.Context, httpStatus int, msg string) {
|
|
c.JSON(httpStatus, Body{Code: httpStatus, Message: msg})
|
|
}
|
|
|