cHelper

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 23 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlignStringMappingArrayFields

func AlignStringMappingArrayFields(data []map[string]string) []map[string]string

func CallerFuncName added in v0.0.52

func CallerFuncName() string

func ChannelAsyncPush added in v0.0.52

func ChannelAsyncPush[T any](ch chan T, data T)

func Chunk added in v0.0.52

func Chunk[T any](data []T, size uint) (result [][]T)

Chunk 数组分片

func Cmd added in v0.0.52

func Cmd(c CmdOption) (result []byte, err error)

func CopyStringMapping

func CopyStringMapping(data map[string]string) (result map[string]string)

func CopyStringMappingArray

func CopyStringMappingArray(data []map[string]string) (result []map[string]string)

func EmbeddingCos added in v0.0.52

func EmbeddingCos(vector1, vector2 []float64) float64

EmbeddingCos 使用cosine计算向量相似度

func EnvToBool

func EnvToBool(name string, value bool) bool

func EnvToInt

func EnvToInt(name string, value int) int

func EnvToString

func EnvToString(name string, value string) string

func GetCurrentDir added in v0.0.52

func GetCurrentDir() string

func GetFieldValue added in v0.0.52

func GetFieldValue(field string, data interface{}) interface{}

func GetFieldValues added in v0.0.52

func GetFieldValues(field string, data interface{}) []interface{}

func GroupBy added in v0.0.52

func GroupBy[T any, P comparable](data []T, key func(item T) (P, bool)) (result map[P][]T)

GroupBy 按字段分组

func InArray added in v0.0.52

func InArray[T comparable](array []T, data T) (result bool)

InArray 数组是否存在该值

func InArrayFloat64

func InArrayFloat64(data float64, array []float64) bool

InArrayFloat64 判断是否在数组中,float64

func InArrayInt

func InArrayInt(data int, array []int) bool

InArrayInt 判断是否在数组中,int

func InArrayString

func InArrayString(data string, array []string) bool

InArrayString 判断是否在数组中,string

func IsBool

func IsBool(value interface{}) bool

IsBool 字符串是否为布尔值

func IsDir added in v0.0.52

func IsDir(f string) bool

IsDir 判断目录

func IsEmpty added in v0.0.7

func IsEmpty(value interface{}) bool

func IsEqualSlice added in v0.0.52

func IsEqualSlice[T comparable](value1, value2 []T) bool

IsEqualSlice 判断数组是否相等

func IsExistsPath

func IsExistsPath(f string) bool

IsExistsPath 判断文件是否存在

func IsFloat added in v0.0.7

func IsFloat(value interface{}) bool

IsFloat checks whether `value` is type of float.

func IsInt

func IsInt(value interface{}) bool

IsInt checks whether `value` is type of int.

func IsMap added in v0.0.7

func IsMap(value interface{}) bool

IsMap checks whether `value` is type of map.

func IsNil added in v0.0.7

func IsNil(value interface{}, traceSource ...bool) bool

func IsNumber

func IsNumber(s string) bool

IsNumber 字符串是否为数字

func IsSlice added in v0.0.7

func IsSlice(value interface{}) bool

IsSlice checks whether `value` is type of slice.

func IsString added in v0.0.52

func IsString(value interface{}) bool

IsString 字符串是否为字符串

func IsStruct added in v0.0.7

func IsStruct(value interface{}) bool

IsStruct checks whether `value` is type of struct.

func IsUint added in v0.0.7

func IsUint(value interface{}) bool

IsUint checks whether `value` is type of uint.

func KeyBy added in v0.0.52

func KeyBy[T any, P comparable](data []T, key func(item T) (P, bool)) (result map[P]T)

KeyBy 按字段转map

func MappingBy added in v0.0.52

func MappingBy[T any, K, V comparable](data []T, f func(item T) (K, V)) (result map[K]V)

MappingBy 使用指定字段组成map

func Md5

func Md5(data []byte) string

func MkDirAll added in v0.0.52

func MkDirAll(f string, perm os.FileMode) (err error)

func OrderBy added in v0.0.52

func OrderBy[T any](data []T, compare func(first, second T) (result bool))

OrderBy 按字段排序

func PasswordHash added in v0.0.52

func PasswordHash(password string) (hash string, err error)

func PasswordVerify added in v0.0.52

func PasswordVerify(password, hash string) bool

func Pluck added in v0.0.52

func Pluck[T any, P comparable](array []T, key func(item T) P) (result []P)

Pluck 取字段值

func PrintMemory added in v0.0.52

func PrintMemory(ctx context.Context, interval int64, handle func(ctx context.Context, mem *MemoryStatus))

func RandomInt

func RandomInt(min, max int) int

RandomInt 生成随机整数

func RandomStr

func RandomStr(length int, randomType RandomType) string

func Recover added in v0.3.2

func Recover() func()

func ReplaceAll

func ReplaceAll(src string, old []string, new string) string

ReplaceAll 多个字符串同时替换为同一个

func SHA1 added in v0.0.52

func SHA1(data string) string

func StructSliceToStructSlice added in v0.0.52

func StructSliceToStructSlice[A, B any](data []A, f func(item A) (result B)) []B

func ToBool

func ToBool(s string) bool

ToBool 字符串转布尔值

func ToCamel added in v0.0.52

func ToCamel(data string) string

func ToCamelWithChars added in v0.0.52

func ToCamelWithChars(data string, chars []string) string

func ToFloat32

func ToFloat32(s string) float32

ToFloat32 字符串转32位浮点数

func ToFloat64

func ToFloat64(s string) float64

ToFloat64 字符串转64位浮点数

func ToInt

func ToInt(s string) int

ToInt 字符串转int

func ToInt32

func ToInt32(s string) int32

ToInt32 字符串转int32

func ToInt64

func ToInt64(s string) int64

ToInt64 字符串转int64

func ToInt8

func ToInt8(s string) int8

ToInt8 字符串转int8

func ToSnake added in v0.0.52

func ToSnake(data string) string

func ToSnakeWithChar added in v0.0.52

func ToSnakeWithChar(data string, r rune) string

func ToString

func ToString(data interface{}) string

ToString 所有类型转字符串

func ToUint

func ToUint(s string) uint

ToUint 字符串转uint

func ToUint32

func ToUint32(s string) uint32

ToUint32 字符串转uint32

func ToUint64

func ToUint64(s string) uint64

ToUint64 字符串转uint64

func ToUint8

func ToUint8(s string) uint8

ToUint8 字符串转uint8

func TrimPath added in v0.0.52

func TrimPath(p string) string

func Ucfirst

func Ucfirst(s string) string

Ucfirst 首字母大写

func Unique added in v0.0.52

func Unique[T comparable](data []T) []T

Unique 去重

func Zip added in v0.0.52

func Zip(src string, dest string, ignores ...string) error

Types

type CmdOption added in v0.0.52

type CmdOption struct {
	Command string
	Dir     string
}

type MemoryStatus added in v0.0.52

type MemoryStatus struct {
	Pid  int
	Used int
	G    string
	M    string
	K    string
	Err  error
}

type NumberType added in v0.0.12

type NumberType uint8
const (
	UInt NumberType = iota
	Int
	UFloat
	Float
	Positive
	Negative
	All
)

type RandomType

type RandomType uint8
const (
	RandomType_All RandomType = iota
	RandomType_Number
	RandomType_Char
	RandomType_LowerChar
	RandomType_UpperChar
	RandomType_Symbol
	RandomType_NumberAndSymbol
	RandomType_CharAndSymbol
)

Jump to

Keyboard shortcuts

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