1 Star 1 Fork 1

xiaoyutab / xgotool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
init.go 5.81 KB
一键复制 编辑 原始数据 按行查看 历史
// xgin框架所提供的支持
package xgin
// xgin框架组件定义值
type Config struct {
SuccessMap map[string]any // 成功时追加的map【如果值为time、date、datetime时,会自动转换为当前时间】
ErrorMap map[string]any // 失败时追加的条目【如果值为time、date、datetime时,会自动转换为当前时间】
CheckKey string // Code代码下标
CheckKeySuccess int // 成功的识别代码
CheckKeyNoLogin int // 未登录识别码
CheckKeyParam int // 参数错误识别码
CheckKeyAuth int // 无权限错误识别码
CheckKeyEmpty int // 数据为空识别码
CheckKeyDB int // 数据库错误识别码
CheckKeyDefaultError int // 默认错误识别码
CheckKeyDefaultMsg string // 默认错误msg消息
CheckKeySuccessMsg string // 成功时的MSG返回值
CheckFlag string // 成功/失败的flag鉴定【此处值会返回bool类型的成功/失败】
CheckMsgKey string // 成功/失败时的msg描述项下标
RequestKey string // 返回结果的下标标识
NowTimeKey string // 返回当前时间的下标,空表示不追加此参数
RuntimeKey string // 注入运行时间的下标[单位:毫秒]
ErrorMsgDB string // 数据库错误msg描述
ErrorMsgEmpty string // 查询数据为空
ErrorMsgAuth string // 无权限
ErrorMsgParam string // 参数错误
ErrorMsgNologin string // 未登录 / 登录超时
Pages *PagesStruct // 分页配置结构
}
// 分页返回结构信息
type PagesStruct struct {
TotalKeys string // 总条数的下标信息【最外层】
ListKeys string // 列表数据存储的下标信息
PagesKeys string // 分页结构数据下标
PagesCurrentKeys string // 分页结构.本页下标key
PagesLastKeys string // 分页接口.最后一页
PagesPerKeys string // 分页接口.上一页
PagesTotalKeys string // 分页接口.总数
PagesLimitKeys string // 分页接口.查询条数
}
// 默认配置项信息
var _default Config = Config{
CheckKey: "code",
CheckKeyNoLogin: 5,
CheckKeyParam: 4,
CheckKeyAuth: 3,
CheckKeyEmpty: 2,
CheckKeyDB: 2,
CheckKeyDefaultError: 1,
CheckFlag: "flag",
CheckMsgKey: "msg",
RequestKey: "request",
CheckKeyDefaultMsg: "未知错误",
CheckKeySuccessMsg: "成功",
ErrorMsgDB: "数据库错误",
ErrorMsgEmpty: "查询数据为空",
ErrorMsgAuth: "无权限",
ErrorMsgParam: "参数错误",
ErrorMsgNologin: "未登录 / 登录超时",
Pages: &PagesStruct{
TotalKeys: "total",
ListKeys: "data",
PagesKeys: "pages",
PagesCurrentKeys: "current_page",
PagesLastKeys: "last_page",
PagesPerKeys: "per_page",
PagesTotalKeys: "total",
PagesLimitKeys: "limit",
},
}
// 注入配置项
//
// c 传入配置项
//
// PS:传入配置项时注意,仅CheckKeySuccess允许为0,其余值为0时将会忽略
// PS2:此组件固定返回HTTP状态码为200,并不是根据错误码返回不同的HTTPSTATUS
// PS3:此组件内部分服务使用中间件进行鉴权和验证,所以部分服务可能会无法追加最后的时间、运行时间等参数
func Regedit(c *Config) {
if c == nil {
return
}
_default.CheckKeySuccess = c.CheckKeySuccess
if len(c.ErrorMap) > 0 {
_default.ErrorMap = c.ErrorMap
}
if len(c.SuccessMap) > 0 {
_default.SuccessMap = c.SuccessMap
}
if c.CheckKey != "" {
_default.CheckKey = c.CheckKey
}
if c.CheckKeyNoLogin != 0 {
_default.CheckKeyNoLogin = c.CheckKeyNoLogin
}
if c.CheckKeyParam != 0 {
_default.CheckKeyParam = c.CheckKeyParam
}
if c.CheckKeyAuth != 0 {
_default.CheckKeyAuth = c.CheckKeyAuth
}
if c.CheckKeyEmpty != 0 {
_default.CheckKeyEmpty = c.CheckKeyEmpty
}
if c.CheckKeyDB != 0 {
_default.CheckKeyDB = c.CheckKeyDB
}
if c.CheckKeyDefaultError != 0 {
_default.CheckKeyDefaultError = c.CheckKeyDefaultError
}
if c.CheckFlag != "" {
_default.CheckFlag = c.CheckFlag
}
if c.CheckMsgKey != "" {
_default.CheckMsgKey = c.CheckMsgKey
}
if c.RequestKey != "" {
_default.RequestKey = c.RequestKey
}
if c.NowTimeKey != "" {
_default.NowTimeKey = c.NowTimeKey
}
if c.RuntimeKey != "" {
_default.RuntimeKey = c.RuntimeKey
}
if c.CheckKeyDefaultMsg != "" {
_default.CheckKeyDefaultMsg = c.CheckKeyDefaultMsg
}
if c.CheckKeySuccessMsg != "" {
_default.CheckKeySuccessMsg = c.CheckKeySuccessMsg
}
if c.ErrorMsgDB != "" {
_default.ErrorMsgDB = c.ErrorMsgDB
}
if c.ErrorMsgEmpty != "" {
_default.ErrorMsgEmpty = c.ErrorMsgEmpty
}
if c.ErrorMsgAuth != "" {
_default.ErrorMsgAuth = c.ErrorMsgAuth
}
if c.ErrorMsgParam != "" {
_default.ErrorMsgParam = c.ErrorMsgParam
}
if c.ErrorMsgNologin != "" {
_default.ErrorMsgNologin = c.ErrorMsgNologin
}
if c.Pages != nil {
if c.Pages.TotalKeys != "" {
_default.Pages.TotalKeys = c.Pages.TotalKeys
}
if c.Pages.ListKeys != "" {
_default.Pages.ListKeys = c.Pages.ListKeys
}
if c.Pages.PagesKeys != "" {
_default.Pages.PagesKeys = c.Pages.PagesKeys
}
if c.Pages.PagesCurrentKeys != "" {
_default.Pages.PagesCurrentKeys = c.Pages.PagesCurrentKeys
}
if c.Pages.PagesLastKeys != "" {
_default.Pages.PagesLastKeys = c.Pages.PagesLastKeys
}
if c.Pages.PagesPerKeys != "" {
_default.Pages.PagesPerKeys = c.Pages.PagesPerKeys
}
if c.Pages.PagesTotalKeys != "" {
_default.Pages.PagesTotalKeys = c.Pages.PagesTotalKeys
}
if c.Pages.PagesLimitKeys != "" {
_default.Pages.PagesLimitKeys = c.Pages.PagesLimitKeys
}
}
}
Go
1
https://gitee.com/xiaoyutab/xgotool.git
git@gitee.com:xiaoyutab/xgotool.git
xiaoyutab
xgotool
xgotool
v0.3.9

搜索帮助