utils

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const Charset = "#abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789@"

Charset defines the set of characters to be used in generating random strings

Variables

This section is empty.

Functions

func BytesToGB

func BytesToGB(bytes uint64) float64

BytesToGB converts a given size in bytes to gigabytes (GB).

func DeepMergeMaps

func DeepMergeMaps(base, news map[string]interface{})

func FlushToDisk

func FlushToDisk(fd *os.File) error

FlushToDisk 封装了文件的 Sync 和 Close 操作,减少重复代码

func Int64ToUint64Safe

func Int64ToUint64Safe(s int64) (uint64, error)

把 int64 转 uint64 前做安全检查(防负)

func IsDir

func IsDir(path string) bool

IsDir check if the path is a directory !IsDir 就可以检查是否为文件

func IsExist

func IsExist(dirPath string) bool

IsExist checked directory is exist

func IsStrictNumber

func IsStrictNumber(s string) (isNumber bool, isNegative bool, isFloat bool)

第一个 bool 值为 true 就是数字,第二个 bool 是负数就是 true ,第三个 bool 是小数 3 个 true 就是 -3.1415927

func NewULID

func NewULID() string

func NotNullString

func NotNullString(s string) bool

func RandomString

func RandomString(length int) string

RandomString returns a string of the specified length composed of characters from Charset

func ReleaseToPool

func ReleaseToPool(pools ...Reusable)

ReleaseToPool releases one or more Reusable objects back to their respective pools. It accepts a variadic parameter of Reusable objects and returns them to the pool for reuse, helping to reduce memory allocations and improve performance.

func SearchInMap

func SearchInMap(m map[string]any, key string) []any

func SplitArgs

func SplitArgs(args []string) []string

SplitArgs splits command-line arguments by "=" if present

func TrimDaemon

func TrimDaemon(args []string) []string

TrimDaemon removes the "-daemon" or "--daemon" arguments from os.Args

func Uint64ToInt64Safe

func Uint64ToInt64Safe(u uint64) (int64, error)

把 uint64 转 int64 前做安全检查

Types

type Reusable

type Reusable interface {
	ReleaseToPool()
}

Jump to

Keyboard shortcuts

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