Documentation
¶
Index ¶
- Constants
- Variables
- func AppBatchCreate[T any](ctx context.Context, app *application.Application, objName string, records []T) error
- func AppBatchCreateReturnRecordID[T any](ctx context.Context, app *application.Application, objName string, records []T) (ids []int64, err error)
- func AppBatchDelete(ctx context.Context, app *application.Application, objName string, ids []int64) error
- func AppBatchDeleteByCond(ctx context.Context, app *application.Application, objName string, ...) error
- func AppBatchQuery[T BaseLookup](ctx context.Context, app *application.Application, options ...q.Option) ([]*T, error)
- func AppBatchUpdate(ctx context.Context, app *application.Application, objName string, ...) error
- func BatchCreate[T any](ctx context.Context, objName string, records []T) error
- func BatchCreateReturnRecordID[T any](ctx context.Context, objName string, records []T) (ids []int64, err error)
- func BatchDelete(ctx context.Context, objName string, ids []int64) error
- func BatchDeleteByCond(ctx context.Context, objName string, cond interface{}) error
- func BatchQuery[T BaseLookup](ctx context.Context, options ...q.Option) ([]*T, error)
- func BatchUpdate(ctx context.Context, objName string, recordMap map[int64]interface{}) error
- func ChunkMap[K comparable, V any](m map[K]V, limit int) []map[K]V
- func ChunkSlice[T any](slice []T, limit int) [][]T
- func CompressImage(imgBytes []byte, quality int) ([]byte, error)
- func GetENFromMultilingual(ml faassdk.Multilingual) string
- func GetObjectAllFields(ctx context.Context, objName string) ([]string, error)
- func GetStructJsonTags(rts ...reflect.Type) (tags []string)
- func GetStructTags(tagName string, rts ...reflect.Type) (tags []string)
- func GetZHFromMultilingual(ml faassdk.Multilingual) string
- func Init()
- func IsDev(ctx context.Context) (bool, error)
- func SetMultilingual(m Multilingual) faassdk.Multilingual
- func ToString(data any) string
- func UnmarshalFromFlowVariables(variables map[string]structs.CfVariable, key string, dist any) error
- type BaseLookup
- type ErrorCode
- type FlowLookup
- type IDLookup
- type Lookup
- type Multilingual
- type NameLookup
- type OpenAPILabelOption
- type OpenAPIOption
- type Result
- func (r *Result) Error(ec ErrorCode) (*Result, error)
- func (r *Result) ErrorWithMessage(message string) (*Result, error)
- func (r *Result) FailWithMessage(data interface{}, message string) (*Result, error)
- func (r *Result) Success(data interface{}) (*Result, error)
- func (r *Result) SuccessWithMessage(data interface{}, message string) (*Result, error)
- type TimeLookup
Constants ¶
const Version = "v0.0.1"
Version 版本号
Variables ¶
var ( ParamsError = ErrorCode{Code: 10001, Message: "params error"} SysError = ErrorCode{Code: 20001, Message: "system error"} TimeoutError = ErrorCode{Code: 20002, Message: "invoke timeout"} ApaasError = ErrorCode{Code: 20003, Message: "aPaaS error"} NoPermissionError = ErrorCode{Code: 20004, Message: "no permission"} )
Functions ¶
func AppBatchCreate ¶
func AppBatchCreate[T any](ctx context.Context, app *application.Application, objName string, records []T) error
AppBatchCreate 使用OpenAPI批量创建
func AppBatchCreateReturnRecordID ¶
func AppBatchCreateReturnRecordID[T any](ctx context.Context, app *application.Application, objName string, records []T) (ids []int64, err error)
AppBatchCreateReturnRecordID 使用OpenAPI批量创建并返回记录ID
func AppBatchDelete ¶
func AppBatchDelete(ctx context.Context, app *application.Application, objName string, ids []int64) error
AppBatchDelete 使用OpenAPI批量删除
func AppBatchDeleteByCond ¶
func AppBatchDeleteByCond(ctx context.Context, app *application.Application, objName string, cond interface{}) error
AppBatchDeleteByCond 使用OpenAPI通过筛选条件批量删除
func AppBatchQuery ¶
func AppBatchQuery[T BaseLookup](ctx context.Context, app *application.Application, options ...q.Option) ([]*T, error)
AppBatchQuery 使用OpenAPI查询所有记录
func AppBatchUpdate ¶
func AppBatchUpdate(ctx context.Context, app *application.Application, objName string, recordMap map[int64]interface{}) error
AppBatchUpdate 使用OpenAPI批量更新
func BatchCreate ¶
BatchCreate 批量创建
func BatchCreateReturnRecordID ¶
func BatchCreateReturnRecordID[T any](ctx context.Context, objName string, records []T) (ids []int64, err error)
BatchCreateReturnRecordID 批量创建并返回记录ID
func BatchDelete ¶
BatchDelete 批量删除
func BatchDeleteByCond ¶
BatchDeleteByCond 通过筛选条件批量删除
func BatchQuery ¶
BatchQuery 查询所有记录
records, err := xtool.BatchQuery[xtool.IDLookup](context.Background(),
q.Object("ObjName"),
q.Select("_id"),
q.Where(cond.Gt("_createdAt", 1735660800000)),
q.Offset(0),
q.Limit(10),
q.OrderBy(
q.OrderByAsc("_createdAt"),
q.OrderByDesc("_id"),
),
)
func BatchUpdate ¶
BatchUpdate 批量更新
func ChunkMap ¶
func ChunkMap[K comparable, V any](m map[K]V, limit int) []map[K]V
ChunkMap 将map分成多份小map
func CompressImage ¶
CompressImage 接受一个图片字节切片和压缩质量 返回压缩后的图片字节切片
func GetENFromMultilingual ¶
func GetENFromMultilingual(ml faassdk.Multilingual) string
GetENFromMultilingual 从Multilingual中获取英文
func GetObjectAllFields ¶
GetObjectAllFields 获取对象的所有字段
func GetStructJsonTags ¶
GetStructJsonTags 获取结构体的json tag
func GetStructTags ¶
GetStructTags 获取结构体的指定tag
func GetZHFromMultilingual ¶
func GetZHFromMultilingual(ml faassdk.Multilingual) string
GetZHFromMultilingual 从Multilingual中获取中文
func SetMultilingual ¶
func SetMultilingual(m Multilingual) faassdk.Multilingual
SetMultilingual 设置多语字段
func UnmarshalFromFlowVariables ¶
func UnmarshalFromFlowVariables(variables map[string]structs.CfVariable, key string, dist any) error
UnmarshalFromFlowVariables 从流程参数中通过key来反序列化(仅供aPaaS1.0使用)
Types ¶
type FlowLookup ¶
type FlowLookup struct {
ID int64 `json:"id"`
I18nName *faassdk.Multilingual `json:"i18n_name"`
Name string `json:"name"`
}
FlowLookup 流程中的对象
func (FlowLookup) GetRecordId ¶
func (l FlowLookup) GetRecordId() int64
type IDLookup ¶
type IDLookup struct {
ID int64 `json:"_id"`
}
IDLookup 仅仅含有_id的Lookup
func (IDLookup) GetRecordId ¶
type Lookup ¶
type Lookup struct {
ID int64 `json:"_id"`
Name *faassdk.Multilingual `json:"_name"`
CreatedAt int64 `json:"_createdAt"`
UpdatedAt int64 `json:"_updatedAt"`
}
Lookup 昆仑对象
func (Lookup) GetRecordId ¶
type Multilingual ¶
Multilingual 多语(OpenAPI查出来的多语类型)
type NameLookup ¶
type NameLookup struct {
ID int64 `json:"_id"`
Name *faassdk.Multilingual `json:"_name"`
}
NameLookup 带_id和_name的Lookup
func (NameLookup) GetRecordId ¶
func (l NameLookup) GetRecordId() int64
type OpenAPILabelOption ¶
type OpenAPILabelOption struct {
ApiName string `json:"apiName"`
Label Multilingual `json:"label"`
}
OpenAPILabelOption OpenAPI的选项带Label
type OpenAPIOption ¶
type OpenAPIOption struct {
ApiName string `json:"apiName"`
}
OpenAPIOption OpenAPI的选项
type Result ¶
type Result struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data"`
RequestId string `json:"request_id"`
}
func (*Result) ErrorWithMessage ¶
func (*Result) FailWithMessage ¶
type TimeLookup ¶
type TimeLookup struct {
ID int64 `json:"_id"`
CreatedAt int64 `json:"_createdAt"`
UpdatedAt int64 `json:"_updatedAt"`
}
TimeLookup 带有更新时间和创建时间的Lookup
func (TimeLookup) GetRecordId ¶
func (l TimeLookup) GetRecordId() int64