代码拉取完成,页面将自动刷新
package gf
import (
"encoding/json"
"net/http"
)
var ResponseDataNil = struct {
}{}
type Response struct {
Code string `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}
func (res Response) GetBytes() []byte {
b, _ := json.Marshal(res)
return b
}
func (res Response) GetString() string {
b, _ := json.Marshal(res)
return string(b[:])
}
func getDefaultErrorResponse(err IError) Response {
var data interface{}
//I18N TODO
if err.Error() == "操作失败" {
data = err.GetDetail()
}
if data == nil {
data = ResponseDataNil
}
return Response{
err.GetCode(), err.GetMsg(), data,
}
}
func getResponseWithCode(code string, data ...interface{}) Response {
if code == "" {
code = SuccessCode
}
msg := DefaultCodeMapping.GetCodeInfo(code)
var r = Response{
Code: code,
Msg: msg,
Data: nil,
}
if data == nil {
return r
}
l := len(data)
if l > 0 {
if l == 1 {
r.Data = data[0]
} else {
r.Data = data
}
}
return r
}
func ResponseStr(c *Context, str string) {
rStr(c, str)
}
func ResponseJson(c *Context, data interface{}) {
rJson(c, data)
}
func rStr(c *Context, str string) {
c.String(http.StatusOK, str)
}
func rJson(c *Context, data interface{}) {
c.JSON(http.StatusOK, data)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。