Files
chain33-im/comet/http/result.go
2022-03-17 15:55:27 +08:00

37 lines
629 B
Go

package http
import "github.com/gin-gonic/gin"
const (
// OK ok
OK = 0
// RequestErr request error
RequestErr = -400
// ServerErr server error
ServerErr = -500
contextErrCode = "context/err/code"
)
type resp struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
func errors(c *gin.Context, code int, msg string) {
c.Set(contextErrCode, code)
c.JSON(200, resp{
Code: code,
Message: msg,
})
}
func result(c *gin.Context, data interface{}, code int) {
c.Set(contextErrCode, code)
c.JSON(200, resp{
Code: code,
Data: data,
})
}