x

package module
v0.0.0-...-4e33a48 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2025 License: MIT Imports: 26 Imported by: 1

Documentation

Index

Constants

View Source
const (
	KB
	MB
	GB
	TB
	PB
	EB
)
View Source
const (
	B   = 1
	KiB = 1024 * B
	MiB = 1024 * KiB
	GiB = 1024 * MiB
)
View Source
const CoTimeout = time.Second

Variables

View Source
var ErrAsyncFuncTimeout = errors.New("async func timeout")

Functions

func AESDecrypt

func AESDecrypt(text, key string) (string, error)

AESDecrypt Example of use

decrypted, err := AESDecrypt(encrypted, key)
if err != nil {
	fmt.Println("Error decrypting:", err)
	return
}
fmt.Println("Decrypted:", decrypted)

func AESEncrypt

func AESEncrypt(text, key string) (string, error)

AESEncrypt Example of use

key := "myverystrongpasswordo32bitlength"
password := "mysecretpassword"

encrypted, err := AESEncrypt(password, key)
if err != nil {
	fmt.Println("Error encrypting:", err)
	return
}
fmt.Println("Encrypted:", encrypted)

func ByteFormat

func ByteFormat(b int64) string

ByteFormat wraps global Bytes's Format function.

func ByteParse

func ByteParse(val string) (int64, error)

ByteParse wraps global Bytes's Parse function.

func ByteToFloat64

func ByteToFloat64(bytes []byte) float64

ByteToFloat64 byte转Float64

func BytesToInt

func BytesToInt(bys []byte) int

func BytesToInt64

func BytesToInt64(bys []byte) int64

func Co

func Co(asyncFunc AsyncFunc, timeout time.Duration) error

Co Description of function usage

errCo := x.Co(func(c context.Context) error {
	return f.xxx(ctx, aa, bb)
}, x.CoTimeout)
defer func() {
	if errCo != nil {
		if errors.Is(errCo, x.ErrAsyncFuncTimeout) {
			elog.Warn("file_vo_fill_tags", elog.FieldCtxTid(ctx.Request.Context()), l.E(err))
		} else {
			elog.Error("file_vo_fill_tags", elog.FieldCtxTid(ctx.Request.Context()), l.E(err))
		}
	}
}()

func Decimal

func Decimal(v float64) float64

func DeepCopy

func DeepCopy(dst, src interface{}) error

DeepCopy 深度拷贝

func Difference

func Difference(slice1, slice2 []string) []string

Difference 求差集 slice1-并集

func DownloadPictureBytes

func DownloadPictureBytes(url string, timeout time.Duration) (res []byte, err error)

func E

func E(msg string, errors ...error) error

func Float64ToByte

func Float64ToByte(float float64) []byte

Float64ToByte Float64转byte

func GetCurrentDirectory

func GetCurrentDirectory() string

GetCurrentDirectory ...

func Go

func Go(fn func())

Go goroutine

func Hash

func Hash(s string) uint32

func I2S

func I2S[T Int](i T) string

func InputCheck

func InputCheck(input string) bool

func Int64ToBytes

func Int64ToBytes(data int64) []byte

func IntToBytes

func IntToBytes(n int) []byte

func Intersect

func Intersect(slice1, slice2 []string) []string

Intersect 求交集

func Ints2String

func Ints2String(ints []int) string

func IsFileExists

func IsFileExists(path string) (bool, error)

IsFileExists ...

func IsSliceContain

func IsSliceContain(slice []string, v string) bool

func IsSliceEqual

func IsSliceEqual(a, b interface{}) bool

IsSliceEqual ..

func Kv2MapInt

func Kv2MapInt(in []Kv) (out map[int]int)

func Kv2MapStr

func Kv2MapStr(in []Kv) (out map[string]string)

func KvFormat

func KvFormat(in []Kv) string

KvFormat TCP:9001,TCP:9003

func LabelsToString

func LabelsToString(labels map[string]string) string

func MapKeyString2Int

func MapKeyString2Int(in map[string]int) (out map[int]int)

func MergeLabels

func MergeLabels(old map[string]string, new map[string]string) map[string]string

MergeLabels merge label the new map will overwrite the old one. e.g. new: {"foo": "newbar"} old: {"foo": "bar"} will return {"foo": "newbar"}

func Page

func Page(from, to, size int64, fn func(from, to int64) error) error

Page parses the function call by size from to, with closed intervals. For example: from=0 to=100 size=10 then the function is called 10 times, each time with from=0 to=10, from=10 to=20, from=20 to=30, ... , from=90 to=100

func RandStringBytes

func RandStringBytes(n int) string

func RunWithRecover

func RunWithRecover(f func())

RunWithRecover

@Description: Filter Log Keywords RunWithRecover
@param f

func S2I64

func S2I64(str string) int64

func S2UI64

func S2UI64(str string) uint64

func SafeFunc

func SafeFunc(fn func()) (err error)

func Strings2Map

func Strings2Map(ss []string) map[string]struct{}

func SyncMapLen

func SyncMapLen(m *sync.Map) int

func UI2S

func UI2S[T Uint](i T) string

func Union

func Union(slice1, slice2 []string) []string

Union 求并集

Types

type AsyncFunc

type AsyncFunc func(ctx context.Context) error

type Bytes

type Bytes struct{}

Bytes struct

func New

func New() *Bytes

New creates a Bytes instance.

func (*Bytes) Format

func (*Bytes) Format(b int64) string

Format formats bytes integer to human readable string. For example, 31323 bytes will return 30.59KB.

func (*Bytes) Parse

func (*Bytes) Parse(value string) (i int64, err error)

Parse parses human readable bytes string to bytes integer. For example, 6GB (6G is also valid) will return 6442450944.

type Int

type Int interface {
	~int8 | ~int16 | ~int32 | ~int64 | ~int
}

type Kv

type Kv struct {
	Key   interface{} `json:"key"`
	Value interface{} `json:"value"`
}

func KvUnFormat

func KvUnFormat(in string) []Kv

KvUnFormat TCP:9001,TCP:9003

func MapInt2Kv

func MapInt2Kv(in map[int]int) []Kv

func MapString2Kv

func MapString2Kv(in map[string]string) []Kv

type Uint

type Uint interface {
	~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uint
}

Jump to

Keyboard shortcuts

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