Documentation ¶
Index ¶
- Constants
- Variables
- func CountTop(ctx context.Context, collection *mongo.Collection, key string, top int) (ret []struct{ ... }, err error)
- func CreateResponse(c *gin.Context, code int, data interface{})
- func ExportFromList(c *gin.Context, exportList [][]string, defs MongoDBDefs, filename string)
- func ExportFromMongoDB(c *gin.Context, collection *mongo.Collection, filter interface{}, ...)
- func MarshalBasicBson(d bson.RawValue) (r string)
- type ExportHostsResp
- type ExportProgress
- type FilterContent
- type FilterQuery
- type FilterRule
- type ModelPage
- type MongoDBDefs
- type MongoElem
- type MongoExists
- type MongoGte
- type MongoInside
- type MongoLte
- type MongoNe
- type MongoNinside
- type MongoRegex
- type PageFunc
- type PageFuncForModal
- type PageOption
- type PageRequest
- type PageResponse
- type PageSearch
- type Response
Constants ¶
View Source
const ( MongoTimeout = 30 * time.Second DefaultPage = 1 DefaultPageSize = 100 )
View Source
const ( SuccessCode = iota AuthFailedErrorCode DuplicateFieldErrorCode DBOperateErrorCode RedisOperateErrorCode ParamInvalidErrorCode DBNoRowAffectedErrorCode ErrorIDLen ErrorID UnknownErrorCode TimeOutErrorCode RemoteAllFailedErrorCode ProjectIDRespect SomeFieldIsNull ExceedLimitErrorCode SSO_ERROR OTPErrorCode PasswordNeedChanged NeedCaptchaCheck LoginIpNotInWhiteList UserLocked )
Variables ¶
View Source
var ErrorDescriptions = map[int]string{ SuccessCode: "success", AuthFailedErrorCode: "auth failed", DuplicateFieldErrorCode: "duplicate field", DBOperateErrorCode: "db operate error", RedisOperateErrorCode: "redis operate error", ParamInvalidErrorCode: "param invalid", DBNoRowAffectedErrorCode: "db no row affected", TemporarilyUnavailable: "resource temporarily unavailable", ErrorIDLen: "ID MAX LEN IS 1-15", ErrorID: "ID ONLY SYUUPRT 'A-Z/a-z/0-9/-/_'", UnknownErrorCode: "unknown error", ProjectIDRespect: "PROJECT ID REPECT", SomeFieldIsNull: "SOME FIELD IS NUL", TimeOutErrorCode: "get result timeout", RemoteAllFailedErrorCode: "all remote instance failed", SSO_ERROR: "sso error", OTPErrorCode: "otp required", PasswordNeedChanged: "password has not been updated for a long time", NeedCaptchaCheck: "need captcha check", LoginIpNotInWhiteList: "login ip not in whitelist", UserLocked: "user locked", }
Functions ¶
func CreateResponse ¶
func ExportFromList ¶
func ExportFromList(c *gin.Context, exportList [][]string, defs MongoDBDefs, filename string)
func ExportFromMongoDB ¶
func ExportFromMongoDB(c *gin.Context, collection *mongo.Collection, filter interface{}, defs MongoDBDefs, filename string)
func MarshalBasicBson ¶
Types ¶
type ExportHostsResp ¶
type ExportHostsResp struct { Code int `json:"code"` Msg string `json:"msg"` Data *ExportProgress `json:"data"` }
type ExportProgress ¶
type FilterContent ¶
type FilterContent struct { Key string `json:"key" binding:"required" bson:"key"` Rules []FilterRule `json:"rules" binding:"required,dive" bson:"rules"` Condition string `json:"condition" binding:"required,oneof=$and $or $nor" bson:"condition"` }
type FilterQuery ¶
type FilterQuery struct { Filter []FilterContent `json:"filter" binding:"dive" bson:"filter"` Condition string `json:"condition" binding:"oneof=$and $or $nor" bson:"condition"` }
func BindFilterQuery ¶
func BindFilterQuery(c *gin.Context) (*FilterQuery, error)
func (*FilterQuery) Transform ¶
func (f *FilterQuery) Transform() bson.M
type FilterRule ¶
type FilterRule struct { Operator string `json:"operator" binding:"required,oneof=$eq $gt $gte $in $lt $lte $ne $nin $regex $time" bson:"operator"` Value interface{} `json:"value" binding:"required" bson:"value"` }
type ModelPage ¶
type ModelPage struct { Total int64 `json:"total"` Count int64 `json:"count"` Pages int64 `json:"pages"` Page int64 `json:"page"` PageSize int64 `json:"page_size"` HasPrev bool `json:"has_prev"` HasNext bool `json:"has_next"` Items []interface{} `json:"items"` }
func DBModelPaginate ¶
func DBModelPaginate(collection *mongo.Collection, pageOption PageOption, pageFunc PageFuncForModal) (*ModelPage, error)
type MongoDBDefs ¶
type MongoExists ¶
type MongoExists struct {
Value interface{} `bson:"$exists"` // 传入数组类型
}
type MongoInside ¶
type MongoInside struct {
Inside interface{} `bson:"$in"` // 传入数组类型
}
type MongoNinside ¶
type MongoNinside struct {
Value interface{} `bson:"$nin"` // 传入数组类型
}
type MongoRegex ¶
type MongoRegex struct {
Regex string `bson:"$regex"`
}
type PageFuncForModal ¶
type PageOption ¶
type PageRequest ¶
type PageResponse ¶
type PageResponse struct { Total int64 `json:"total" bson:"total"` Page int64 `json:"page"` PageSize int64 `json:"page_size"` }
PageResponse 返回定义
func DBAggregatePaginate ¶
func DBAggregatePaginate(collection *mongo.Collection, pipe []interface{}, pageOption PageSearch, pageFunc PageFunc) (*PageResponse, error)
func DBSearchPaginate ¶
func DBSearchPaginate(collection *mongo.Collection, pageOption PageSearch, pageFunc PageFunc, opts ...*options.FindOptions) (*PageResponse, error)
DBSearchPaginate 分页查询
type PageSearch ¶
PageSearch 查询定义
Click to show internal directories.
Click to hide internal directories.