xtool

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 23 Imported by: 0

README

XTOOL

xtool是为aPaaS、Lark提供的golang工具集

Documentation

Index

Constants

View Source
const Version = "v0.0.1"

Version 版本号

Variables

View Source
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

func BatchCreate[T any](ctx context.Context, objName string, records []T) error

BatchCreate 批量创建

func BatchCreateReturnRecordID

func BatchCreateReturnRecordID[T any](ctx context.Context, objName string, records []T) (ids []int64, err error)

BatchCreateReturnRecordID 批量创建并返回记录ID

func BatchDelete

func BatchDelete(ctx context.Context, objName string, ids []int64) error

BatchDelete 批量删除

func BatchDeleteByCond

func BatchDeleteByCond(ctx context.Context, objName string, cond interface{}) error

BatchDeleteByCond 通过筛选条件批量删除

func BatchQuery

func BatchQuery[T BaseLookup](ctx context.Context, options ...q.Option) ([]*T, error)

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

func BatchUpdate(ctx context.Context, objName string, recordMap map[int64]interface{}) error

BatchUpdate 批量更新

func ChunkMap

func ChunkMap[K comparable, V any](m map[K]V, limit int) []map[K]V

ChunkMap 将map分成多份小map

func ChunkSlice

func ChunkSlice[T any](slice []T, limit int) [][]T

ChunkSlice 将slice分成多份小slice

func CompressImage

func CompressImage(imgBytes []byte, quality int) ([]byte, error)

CompressImage 接受一个图片字节切片和压缩质量 返回压缩后的图片字节切片

func GetENFromMultilingual

func GetENFromMultilingual(ml faassdk.Multilingual) string

GetENFromMultilingual 从Multilingual中获取英文

func GetObjectAllFields

func GetObjectAllFields(ctx context.Context, objName string) ([]string, error)

GetObjectAllFields 获取对象的所有字段

func GetStructJsonTags

func GetStructJsonTags(rts ...reflect.Type) (tags []string)

GetStructJsonTags 获取结构体的json tag

func GetStructTags

func GetStructTags(tagName string, rts ...reflect.Type) (tags []string)

GetStructTags 获取结构体的指定tag

func GetZHFromMultilingual

func GetZHFromMultilingual(ml faassdk.Multilingual) string

GetZHFromMultilingual 从Multilingual中获取中文

func Init

func Init()

Init 初始化

func IsDev

func IsDev(ctx context.Context) (bool, error)

IsDev 是否是测试环境

func SetMultilingual

func SetMultilingual(m Multilingual) faassdk.Multilingual

SetMultilingual 设置多语字段

func ToString

func ToString(data any) string

ToString 转成字符串

func UnmarshalFromFlowVariables

func UnmarshalFromFlowVariables(variables map[string]structs.CfVariable, key string, dist any) error

UnmarshalFromFlowVariables 从流程参数中通过key来反序列化(仅供aPaaS1.0使用)

Types

type BaseLookup

type BaseLookup interface {
	GetRecordId() int64
}

BaseLookup 泛型

type ErrorCode

type ErrorCode struct {
	Code    int
	Message string
}

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

func (l IDLookup) GetRecordId() int64

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

func (l Lookup) GetRecordId() int64

type Multilingual

type Multilingual struct {
	ZH string `json:"zh_CN"`
	EN string `json:"en_US"`
}

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 NewResult

func NewResult() *Result

func (*Result) Error

func (r *Result) Error(ec ErrorCode) (*Result, error)

func (*Result) ErrorWithMessage

func (r *Result) ErrorWithMessage(message string) (*Result, error)

func (*Result) FailWithMessage

func (r *Result) FailWithMessage(data interface{}, message string) (*Result, error)

func (*Result) Success

func (r *Result) Success(data interface{}) (*Result, error)

func (*Result) SuccessWithMessage

func (r *Result) SuccessWithMessage(data interface{}, message string) (*Result, error)

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

Directories

Path Synopsis
bot
q

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL