You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
710 B
41 lines
710 B
package bean
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
var Response = &response{}
|
|
|
|
type response struct {
|
|
Code int `json:"code"`
|
|
Msg string `json:"msg"`
|
|
Data interface{} `json:"data"`
|
|
}
|
|
|
|
// @Title 返回成功
|
|
func (r *response) ResultSuc(c *gin.Context, msg string, data interface{}) {
|
|
c.JSON(http.StatusOK, response{
|
|
Code: 0,
|
|
Msg: msg,
|
|
Data: data,
|
|
})
|
|
}
|
|
|
|
// @Title 返回失败
|
|
func (r *response) ResultFail(c *gin.Context, code int, msg string, data ...interface{}) {
|
|
if len(data) > 0 {
|
|
c.JSON(http.StatusOK, response{
|
|
Code: code,
|
|
Msg: msg,
|
|
Data: data[0],
|
|
})
|
|
} else {
|
|
c.JSON(http.StatusOK, response{
|
|
Code: code,
|
|
Msg: msg,
|
|
Data: nil,
|
|
})
|
|
}
|
|
}
|