1 Star 0 Fork 0

zbfwater/zhang

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
api_base.go 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
zhang.ge 提交于 2021-06-07 01:46 +08:00 . upgrade
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")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/zbfwater/zhang.git
git@gitee.com:zbfwater/zhang.git
zbfwater
zhang
zhang
ea8c6407341b

搜索帮助