代码拉取完成,页面将自动刷新
package zweb
import (
"gitee.com/zbfwater/zhang/z"
"gitee.com/zbfwater/zhang/zlog"
"github.com/gogf/gf/net/ghttp"
"log"
"runtime"
)
type ApiBase struct {
}
type Api interface {
Register(*ghttp.Server)
}
func (api *ApiBase) Ok(data interface{}) z.Map {
return z.Map{
"status": true,
"data": data,
}
}
func (api *ApiBase) Error(msg string, err error) z.Map {
pc, file, line, ok := runtime.Caller(1)
log.Print(pc, file, line, ok)
if err != nil {
zlog.LogError(err)
if msg == "" {
msg = err.Error()
}
}
return z.Map{
"status": false,
"msg": msg,
}
}
func (api *ApiBase) OkResult(data interface{}, r *ghttp.Request) error {
return r.Response.WriteJson(api.Ok(data))
}
func (api *ApiBase) ErrorResult(msg string, error error, r *ghttp.Request) error {
return r.Response.WriteJson(api.Error(msg, error))
}
func (api *ApiBase) Result(data interface{}, err error, r *ghttp.Request) error {
if err != nil {
return api.ErrorResult("", err, r)
}
return api.OkResult(data, r)
}
func (api *ApiBase) Result2(result *z.Result, r *ghttp.Request) error {
return r.Response.WriteJson(*result)
}
func (api *ApiBase) GetToken(r *ghttp.Request) string {
return r.Header.Get("token")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。