Documentation
¶
Index ¶
- func CalculateRealSize(v interface{}) int
- func CamelToSnake(s string) string
- func CheckModelValid(model map[string]any) error
- func CollectToMap[T any, K comparable, V any](in []T, keyOf func(T) K, valOf func(T) V) map[K]V
- func ConvertByJSON[A any, B any](input A) (B, error)
- func DeRef(row []interface{}) []interface{}
- func DefaultTemplateRender(inputText string, sourceMap map[string]any, result *string) error
- func DownloadToTempDir(url string) (*os.File, error)
- func FileExists(filePath string) bool
- func Filter[T any](endpoints []T, f func(endpoint T) bool) []T
- func Find[T any](list []T, predicate func(T) bool) (T, bool)
- func GenerateShortID() (string, error)
- func GenerateShortIDWithDigits(digits uint8) (string, error)
- func GetByPath(data any, path []any) any
- func GetSuffix(str string) string
- func GetValue(data map[string]any, expr string) any
- func GzipCompress(input []byte) []byte
- func GzipDecompress(input []byte) []byte
- func HashPassword(password string) (string, error)
- func InLike(target any, list any) bool
- func InSlice(target any, list any) bool
- func InitSnowflake(nodeID int64) (*snowflake.Node, error)
- func IsDataEmpty(v any) bool
- func IsEmpty(s string) bool
- func MapKeys[M ~map[K]V, K comparable, V any](m M) []string
- func MustJSON(v any) datatypes.JSON
- func NumericStringify(v any) string
- func ParseList(v any) []string
- func ParsePathExpr(expr string) []any
- func ParseTemplate(templateText string) (map[string]TemplateNeedle, error)
- func ParseTemplateTest()
- func Ptr[T any](v T) *T
- func RegexReplace(s, pattern, repl string) string
- func RenderTemplateStrictly(templateText string, slots map[string]TemplateNeedle, model map[string]any, ...) string
- func RunParallel[I any, O any](ctx context.Context, inputs []I, workers int, rowId func(I) string, ...) (map[string]O, []error)
- func SaveToWAVFile(filename string, data []byte) (*os.File, error)
- func ScryptHash(password, salt string) (string, error)
- func SendFileChunks(file *os.File, firstSize int, chunkSize int, ch chan []byte)
- func SimplifyHeader(header map[string][]string) map[string]string
- func StreamMap[T any, R any](in []T, f func(T) R) []R
- func Stringify[A any](input A) string
- func Ternary[T any](cond bool, trueVal T, falseVal T) T
- func TernaryFunc[T any](cond bool, trueVal func() T, falseVal T) T
- func TimingMiddlewareLogging(phase string, log string) func()
- func ToFloat64(v any) (float64, bool)
- func UniqueList(items []string) []string
- func UniqueStrings(input []string) []string
- func Uuid() string
- type FlexibleFloat64
- type FlexibleInt64
- type FlexibleInt8
- type HandlerFunc
- type KeyFunc
- type LRUCache
- type Option
- type PageQueryFunc
- type Pair
- type SafeHashSet
- type TemplateNeedle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CamelToSnake ¶ added in v0.1.2
func CheckModelValid ¶ added in v0.1.2
CheckModelValid 检查模型中每个键是否合法:非空且只允许英文、数字、下划线以及中文字符
func CollectToMap ¶ added in v0.1.2
func CollectToMap[T any, K comparable, V any]( in []T, keyOf func(T) K, valOf func(T) V, ) map[K]V
func ConvertByJSON ¶ added in v0.0.7
ConvertByJSON Convert 转换任意类型 A 到类型 B
func DefaultTemplateRender ¶ added in v0.1.2
func FileExists ¶
func GenerateShortID ¶ added in v0.1.2
func GenerateShortIDWithDigits ¶ added in v0.1.2
func GzipCompress ¶
func GzipDecompress ¶
func HashPassword ¶ added in v0.1.2
HashPassword 使用 bcrypt 对密码进行哈希处理
func InitSnowflake ¶ added in v0.1.2
InitSnowflake 初始化 Snowflake 节点
func IsDataEmpty ¶ added in v0.1.2
func MapKeys ¶ added in v0.1.2
func MapKeys[M ~map[K]V, K comparable, V any](m M) []string
func NumericStringify ¶ added in v0.1.2
func ParsePathExpr ¶ added in v0.1.2
ParsePathExpr 将路径字符串(如 用户.好友[0].昵称)解析为 ["用户", "好友", 0, "昵称"]
func ParseTemplate ¶ added in v0.1.2
func ParseTemplate(templateText string) (map[string]TemplateNeedle, error)
ParseTemplate 从模板文本中提取所有占位符,返回键值对:键为参数名称,值为占位符文本
func ParseTemplateTest ¶ added in v0.1.2
func ParseTemplateTest()
func RegexReplace ¶ added in v0.1.2
RegexReplace 用正则表达式将字符串 s 中所有匹配 pattern 的部分替换为 repl
func RenderTemplateStrictly ¶ added in v0.1.2
func RenderTemplateStrictly(templateText string, slots map[string]TemplateNeedle, model map[string]any, strict bool) string
RenderTemplateStrictly 根据传入的模型,将模板中的占位符替换为实际值
func RunParallel ¶ added in v0.1.2
func RunParallel[I any, O any]( ctx context.Context, inputs []I, workers int, rowId func(I) string, function func(context.Context, I) (O, error), ) (map[string]O, []error)
RunParallel 并发执行 fn,按输入顺序返回结果。 - inputs: 要处理的输入切片 - workers: 工作者数量(<=0 视为 1) - fn: 你的任务函数,形如 func(ctx, I) (O, error)
func ScryptHash ¶ added in v0.1.2
func SendFileChunks ¶
func SimplifyHeader ¶ added in v0.0.7
SimplifyHeader 压缩 Header
func TernaryFunc ¶ added in v0.1.2
func TimingMiddlewareLogging ¶ added in v0.1.2
func UniqueList ¶ added in v0.1.2
func UniqueStrings ¶ added in v0.1.2
Types ¶
type FlexibleFloat64 ¶ added in v0.1.2
type FlexibleFloat64 float64
func (*FlexibleFloat64) UnmarshalJSON ¶ added in v0.1.2
func (f *FlexibleFloat64) UnmarshalJSON(b []byte) error
type FlexibleInt64 ¶ added in v0.1.2
type FlexibleInt64 int64
func (*FlexibleInt64) UnmarshalJSON ¶ added in v0.1.2
func (f *FlexibleInt64) UnmarshalJSON(b []byte) error
type FlexibleInt8 ¶ added in v0.1.2
type FlexibleInt8 int8
func (*FlexibleInt8) UnmarshalJSON ¶ added in v0.1.2
func (f *FlexibleInt8) UnmarshalJSON(b []byte) error
type HandlerFunc ¶ added in v0.1.2
type HandlerFunc[T any] func(items []T)
type LRUCache ¶ added in v0.1.2
type LRUCache[K comparable, V any] struct { // contains filtered or unexported fields }
LRUCache 是一个并发安全的泛型 LRU 缓存
func NewLRUCache ¶ added in v0.1.2
func NewLRUCache[K comparable, V any](cap int) *LRUCache[K, V]
NewLRUCache 新建一个最大容量为 cap 的 LRUCache
type Option ¶ added in v0.1.2
type Option[K comparable, V any] func(*LRUCache[K, V])
type PageQueryFunc ¶ added in v0.1.2
type SafeHashSet ¶ added in v0.1.2
type SafeHashSet[T comparable] struct { // contains filtered or unexported fields }
func NewSafeHashSet ¶ added in v0.1.2
func NewSafeHashSet[T comparable]() *SafeHashSet[T]
func ScanAllPages ¶ added in v0.1.2
func ScanAllPages[T any]( ctx context.Context, pageSize int, query PageQueryFunc[T], keyFunc KeyFunc[T], handle HandlerFunc[T], ) (*SafeHashSet[string], error)
func (*SafeHashSet[T]) Add ¶ added in v0.1.2
func (s *SafeHashSet[T]) Add(val T)
func (*SafeHashSet[T]) Has ¶ added in v0.1.2
func (s *SafeHashSet[T]) Has(val T) bool
func (*SafeHashSet[T]) Len ¶ added in v0.1.2
func (s *SafeHashSet[T]) Len() int
func (*SafeHashSet[T]) Remove ¶ added in v0.1.2
func (s *SafeHashSet[T]) Remove(val T)
func (*SafeHashSet[T]) Values ¶ added in v0.1.2
func (s *SafeHashSet[T]) Values() []T
type TemplateNeedle ¶ added in v0.1.2
Click to show internal directories.
Click to hide internal directories.