Documentation
¶
Index ¶
- func DiffBson(origin interface{}, news interface{}, jsonData map[string]interface{}) (bson.M, bson.M)
- func IsNum(s string) bool
- func LimitHandler(l *limiter.Limiter, errBack ...func(*errors.HTTPError, iris.Context)) iris.Handler
- func UTCTrans(utcTime string) (time.Time, error)
- type AliasProcess
- type Config
- type ModelInfo
- type RestApi
- func (rest *RestApi) AddData(ctx iris.Context)
- func (rest *RestApi) DeleteData(ctx iris.Context)
- func (rest *RestApi) EditData(ctx iris.Context)
- func (rest *RestApi) GetAllFunc(ctx iris.Context)
- func (rest *RestApi) GetModelInfo(ctx iris.Context)
- func (rest *RestApi) GetModelInfoList() []ModelInfo
- func (rest *RestApi) GetSingle(ctx iris.Context)
- func (rest *RestApi) NameGetModel(pathname string) (*SingleModel, error)
- func (rest *RestApi) PathGetMid(method string, uri string) (string, string)
- func (rest *RestApi) PathGetModel(pathUri string) *SingleModel
- func (rest *RestApi) UriGetMid(uri string) (string, string)
- type SingleModel
- type SpAliasProcess
- type StructInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiffBson ¶
func DiffBson(origin interface{}, news interface{}, jsonData map[string]interface{}) (bson.M, bson.M)
DiffBson 两个bson.m 对比 获取异同
func LimitHandler ¶
Types ¶
type AliasProcess ¶ added in v0.1.32
type AliasProcess interface {
Alias() string
}
type Config ¶
type Config struct {
Party iris.Party
Mdb *qmgo.Database
Models []*SingleModel
ErrorTrace func(err error, event, from, router string) // error trace func
Generator bool // 生成器模式 若启用则只有一个入口
PrivateContextKey string
PrivateColName string
StructDelimiter string // 内联struct之间的分隔符 默认__ 因为.号会被转义 不要使用. _
SensitiveUri []string // 敏感词库
SensitiveWords []string // 敏感词列表
}
Config 配置文件 敏感词 用于国内的审核 可在model配置文件中配置需要验证的字段 每次数据新增/修改时会进行验证
type ModelInfo ¶ added in v0.2.13
type ModelInfo struct {
MapName string `json:"map_name"`
FullPath string `json:"full_path"`
Alias string `json:"alias"`
Group string `json:"group"`
FieldList []StructInfo `json:"field_list"`
FlatFields []StructInfo `json:"flat_fields"`
}
ModelInfo 模型信息
type RestApi ¶
type RestApi struct {
Cfg *Config
// contains filtered or unexported fields
}
func (*RestApi) DeleteData ¶
DeleteData 删除数据 /{mid:string range(1,32)}
func (*RestApi) GetAllFunc ¶
GetAllFunc 获取所有 page 控制页码 page_size 控制条数 最大均为100 100页 100条 _last mid 大页码通用 _o(asc) _od _s __在左右则为模糊 _s=__赵日天 [字段名] 进行过滤 id=1 最长64位请注意 and关系 _o_[字段名] 进行过滤 _o_id=2 最长64位 or关系
func (*RestApi) GetModelInfo ¶ added in v0.1.49
GetModelInfo 获取模型信息
func (*RestApi) GetModelInfoList ¶ added in v0.1.31
GetModelInfoList 获取详细的模型列表
func (*RestApi) NameGetModel ¶ added in v0.2.8
func (rest *RestApi) NameGetModel(pathname string) (*SingleModel, error)
NameGetModel 根据名称获取model
func (*RestApi) PathGetMid ¶ added in v0.2.8
PathGetMid 根据path提取出mid
func (*RestApi) PathGetModel ¶ added in v0.2.8
func (rest *RestApi) PathGetModel(pathUri string) *SingleModel
PathGetModel 通过路径获取对应的模型信息
type SingleModel ¶
type SingleModel struct {
Prefix string // 路由前缀
Suffix string // 路由后缀
Model interface{} // xorm model
ShowCount bool // 显示搜索数量
ShowDocCount bool // 显示文档数量
AllowGetInfo bool // 允许获取表结构信息
CustomModel func(ctx iris.Context, model *SingleModel) *SingleModel // 记住要进行指针值传递 返回一个新对象 否则会修改原始配置文件
Pk func() []bson.D // 外键
DisablePrivate bool // 禁用私密参数
DisablePrivateMap map[string]bool // 禁用私密参数定制项 key为方法 value为启用与否 前提条件必须启用后才能禁用 而不能禁用后启用
PrivateContextKey string // 上下文key string int uint
PrivateColName string // 数据库字段名 MapName or ColName is ok
AllowMethods []string // allow methods first
DisableMethods []string // get(all) get(single) post put delete
MustSearch bool // 必须搜索模式 会忽略下面的搜索设置强制开启搜索 (非slice|struct|primitive.ObjectID)
AllowSearchFields []string // 搜索的字段 struct名称
InjectParams func(ctx iris.Context) map[string]string // 注入params 用于get请求参数的自定义
GetAllResponseFunc func(ctx iris.Context, result iris.Map, dataList []map[string]interface{}) iris.Map // 返回内容替换的方法
GetAllExtraFilters func(ctx iris.Context) map[string]interface{} // 额外的固定过滤 key(数据库列名) 和 value 若与请求过滤重复则覆盖 优先级最高
GetAllMustFilters map[string]string // 获取全部必须拥有筛选
GetSingleResponseFunc func(ctx iris.Context, item map[string]interface{}) map[string]interface{} // 获取单个返回内容替换的方法
GetSingleExtraFilters func(ctx iris.Context) map[string]interface{} // 额外的固定过滤 key(数据库列名) 和 value 若与请求过滤重复则覆盖 优先级最高
GetSingleMustFilters map[string]string // 获取单个必须拥有筛选
PostValidator interface{} // 新增自定义验证器
PostMustFilters map[string]string // 新增必须存在的参数
PostResponseFunc func(ctx iris.Context, mid string, item interface{}) interface{} //
PostDataParse func(ctx iris.Context, raw interface{}) interface{} //
PutValidator interface{} // 修改验证器
PutDataParse func(ctx iris.Context, mid string, diff bson.M) bson.M //
PutQueryParse func(ctx iris.Context, mid string, query bson.M, data interface{}, privateValue interface{}) bson.M // 修改的时候query可以自定义修改
PutResponseFunc func(ctx iris.Context, mid string) iris.Map // 在修改之前还可以变更一下数据
PutMustFilters map[string]string //
DeleteValidator interface{} // 删除验证器
DeleteResponseFunc func(ctx iris.Context, mid string, item map[string]interface{}, result iris.Map) iris.Map //
SensitiveFields []string // 使用struct name 或者mapname 均可(map对象为bson:)
CacheTime time.Duration // full cache time
GetAllCacheTime time.Duration // get all cache time
GetSingleCacheTime time.Duration // get single cache time
DelayDeleteTime time.Duration // 延迟多久双删 default 500ms
MaxPageSize int64 // max page size limit
MaxPageCount int64 // max page count limit
RateErrorFunc func(*tollerr.HTTPError, iris.Context) //
Rate *limiter.Limiter // all
GetAllRate *limiter.Limiter //
GetSingleRate *limiter.Limiter //
AddRate *limiter.Limiter //
PutRate *limiter.Limiter //
DeleteRate *limiter.Limiter //
// contains filtered or unexported fields
}
SingleModel 单个模型实例 CustomModel 主要用来动态配置项 比如说context变更 pk变更等灵活使用 e.g:
func(ctx iris.Context, model *SingleModel) *SingleModel {
newModel:= new(SingleModel)
*newModel = *model
// 修改配置文件
return newModel
}
type SpAliasProcess ¶ added in v0.1.45
type SpAliasProcess interface {
SpAlias() string
}
type StructInfo ¶ added in v0.2.13
type StructInfo struct {
Name string `json:"name"` // 字段名 struct name
MapName string `json:"map_name"` // 转snake格式的名称
FullName string `json:"full_name"` // [parentStructName][structDelimiter]][structName]
FullMapName string `json:"full_map_name"` // [parentSnakeName][structDelimiter][snakeName]
ParamsKey string `json:"params_key"` // post form key name
CustomTag string `json:"custom_tag"` // 自定义标签信息 mab:
ValidateTag string `json:"validate_tag,omitempty"` // 验证器标签信息
Comment string `json:"comment,omitempty"`
Level string `json:"level"` // parentIndex - .... - self index
Kind string `json:"kind"`
Bson []string `json:"bson"` // bson tag
Types string `json:"types"`
Index int `json:"index,omitempty"`
IsDefaultWrap bool `json:"is_default_wrap,omitempty"`
IsTime bool `json:"is_time,omitempty"`
IsPk bool `json:"is_pk,omitempty"`
IsObjId bool `json:"is_obj_id,omitempty"`
IsCreated bool `json:"is_created,omitempty"`
IsUpdated bool `json:"is_updated,omitempty"`
IsDeleted bool `json:"is_deleted,omitempty"`
IsGeo bool `json:"is_geo,omitempty"`
IsInline bool `json:"is_inline,omitempty"`
Children []StructInfo `json:"children,omitempty"`
ChildrenKind string `json:"children_kind,omitempty"`
}
StructInfo 模型字段信息
func TableNameGetNestedStructMaps ¶ added in v0.2.12
func TableNameReflectFieldsAndTypes ¶ added in v0.2.12
func TableNameReflectFieldsAndTypes(table interface{}, structDelimiter string) []StructInfo
Source Files
¶
Click to show internal directories.
Click to hide internal directories.