1 Star 1 Fork 1

goeoeo / ant-api

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
code.go 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
goeoeo 提交于 2019-11-29 14:26 . ant-api初始化
package entitys
import "fmt"
const (
CodeOK =0
CodeErr =50
CodeNoAuth =51 //您没有执行该操作的权限
CodeTOKENERR =52 //token错误
CodeValidFail =53 //格式验证错误
)
var CodeMsg=map[uint32]string{
CodeErr:"错误",
CodeNoAuth:"您没有执行该操作的权限",
CodeTOKENERR:"token错误",
}
//json数据输出
type JsonResult struct {
Code uint32
Msg string
Data interface{}
}
type WebErr struct {
Code uint32 //错误码
Msg string //展示错误消息
OriginalMsg string //原始的错误消息
}
//构造webErr
func NewWebErr(code uint32, originalMsg ...string) error {
if code == CodeOK {
return nil
}
err := WebErr{Code: code}
if len(originalMsg) > 0 {
err.Msg = originalMsg[0]
err.OriginalMsg = originalMsg[0]
}
//填充msg
if tmpMsg, ok := CodeMsg[code]; ok {
err.Msg = tmpMsg
}
if err.Msg == "" {
err.Msg = "错误未定义"
}
return err
}
func (this WebErr) Error() string {
return this.Msg
}
func (this WebErr) Log() string {
return fmt.Sprintf("Code:%d,Msg:%s,OriginalMsg:%s", this.Code, this.Msg, this.OriginalMsg)
}
Go
1
https://gitee.com/goeoeo/ant-api.git
git@gitee.com:goeoeo/ant-api.git
goeoeo
ant-api
ant-api
a4d54182c883

搜索帮助

53164aa7 5694891 3bd8fe86 5694891