utils

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIpV4Address = errors.New(`invalid ip v4 address`)
	ErrNotFoundIp  = errors.New("not found ip address")
)
View Source
var (
	JsonMarshal   = json.Marshal
	JsonUnmarshal = json.Unmarshal
)
View Source
var (
	YamlMarshal   = yaml.Marshal
	YamlUnmarshal = yaml.Unmarshal
)

Functions

func Abs

func Abs[V kind.Number](value V) V

func Acquire

func Acquire(lock *int64, timeout time.Duration) (token int64)

func Base64Decode

func Base64Decode(src []byte) (dst []byte, err error)

func Base64Decode2String

func Base64Decode2String(src []byte) (data string, err error)

func Base64Encode

func Base64Encode(src []byte) []byte

func Base64Encode2String

func Base64Encode2String(src []byte) string

func Base64UrlDecode

func Base64UrlDecode(src []byte) (dst []byte, err error)

func Base64UrlEncode

func Base64UrlEncode(src []byte) []byte

func BinPath

func BinPath() string

BinPath 获取Bin目录

func Black

func Black(format string, args ...any)

Black 默认输出

func Blue

func Blue(format string, args ...any)

Blue 颜色输出

func Bytes2Bool

func Bytes2Bool(data []byte) bool

Bytes2Bool 字节切片转换为bool

func Bytes2Float64

func Bytes2Float64(data []byte) float64

Bytes2Float64 字节切片转换为float64

func Bytes2Int64

func Bytes2Int64(data []byte) int64

Bytes2Int64 字节切片转换为int64

func Bytes2String

func Bytes2String(data []byte) string

Bytes2String 字节切片转换为字符串

func Bytes2Uint32

func Bytes2Uint32(data []byte) uint32

Bytes2Uint32 字节切片转换为uint32

func Bytes2Uint64

func Bytes2Uint64(data []byte) uint64

Bytes2Uint64 字节切片转换为uint64

func FileExists

func FileExists(fileName string) (exists bool, err error)

FileExists 判断文件是否存在

func FileTime

func FileTime(fileName string) (createTime, lastAccessTime, lastWriteTime int64, err error)

FileTime 获取文件时间

func Fuchsia

func Fuchsia(format string, args ...any)

Fuchsia 颜色输出

func Green

func Green(format string, args ...any)

Green 成功输出

func HMac

func HMac(key []byte, data []byte, hash crypto.Hash) string

HMac HMac算法

func HMacBytes

func HMacBytes(key []byte, data []byte, hash crypto.Hash) []byte

func Hash

func Hash(data []byte, hash crypto.Hash) string

Hash Hash算法

func HashBytes

func HashBytes(data []byte, hash crypto.Hash) []byte

func HashValue

func HashValue(key any) uint32

HashValue 计算任意类型hash值

func HexDecode

func HexDecode(src []byte) (dst []byte, err error)

func HexDecode2String

func HexDecode2String(src []byte) (data string, err error)

func HexEncode

func HexEncode(src []byte) []byte

func HexEncode2String

func HexEncode2String(src []byte) string

func Index4Bit

func Index4Bit(key any, bitCount uint8) uint32

Index4Bit 索引路由方法,值范围为uint32

func Index4Int16

func Index4Int16(key any) int16

Index4Int16 索引路由方法,值范围为int16

func Index4Int8

func Index4Int8(key any) int8

Index4Int8 索引路由方法,值范围为int8

func Index4Uint8

func Index4Uint8(key any) uint8

Index4Uint8 索引路由方法,值范围为uint8

func Ip2Long

func Ip2Long(ip string) (ipVal uint32, err error)

Ip2Long Ip转换为uint32

func Join

func Join[T kind.Integer](sep string, elems ...T) string

func JsonDecode

func JsonDecode(data string, v any) (err error)

JsonDecode ---

func JsonEncode

func JsonEncode(v any) (data string, err error)

JsonEncode ---

func JsonUnmarshalFile

func JsonUnmarshalFile(filePath string, v any) (err error)

JsonUnmarshalFile ---

func LcFirst

func LcFirst(str string) string

func LocalIp

func LocalIp() (ip string, err error)

LocalIp 获取本机Ip

func Long2Ip

func Long2Ip(ipVal uint32) string

Long2Ip uint32转换为Ip

func Md5

func Md5(data []byte) string

Md5 Md5算法

func MkDir

func MkDir(dir string, perm os.FileMode) (err error)

MkDir 创建目录

func ParallelLoad

func ParallelLoad(loadList ...func() error)

func PprofIsRun

func PprofIsRun() bool

PprofIsRun _

func Recover

func Recover(eventName string, f func(args ...any), args ...any)

func Red

func Red(format string, args ...any)

Red 错误输出

func RedFatal

func RedFatal(format string, args ...any)

RedFatal 致命错误输出

func Release

func Release(lock *int64, token int64) (swapped bool)

func Sha1

func Sha1(data []byte) string

Sha1 Sha1算法

func Sha256

func Sha256(data []byte) string

func StartPprof

func StartPprof(addr string, handler http.Handler) error

StartPprof _

func StopPprof

func StopPprof(ctx context.Context) error

StopPprof _

func StopPprofWithTimeout

func StopPprofWithTimeout(seconds int64) error

StopPprofWithTimeout _

func String2Bytes

func String2Bytes(data string) []byte

String2Bytes 字符串转字节切片,注意:转换后不能对字节切片进行修改

func StringInteger

func StringInteger[T kind.Integer](value T) string

func Timeout

func Timeout(timeout time.Duration, handler func(args ...any), args ...any) error

func ToString

func ToString(val any) string

ToString 转为字符串类型

func UcFirst

func UcFirst(str string) string

func YamlDecode

func YamlDecode(data string, v any) (err error)

YamlDecode ---

func YamlEncode

func YamlEncode(v any) (data string, err error)

YamlEncode ---

func YamlUnmarshalFile

func YamlUnmarshalFile(filePath string, v any) (err error)

YamlUnmarshalFile ---

func Yellow

func Yellow(format string, args ...any)

Yellow 警告输出

Types

This section is empty.

Jump to

Keyboard shortcuts

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