utils

package
v2.0.15 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OK 成功返回
	OK = codes.OK

	// CodeCanceled 表示操作已取消(通常由调用者取消)
	CodeCanceled = codes.Canceled

	// CodeUnknown 未知错误
	CodeUnknown = codes.Unknown

	// CodeInvalidArgument 客户端传递了一个无效的参数
	CodeInvalidArgument = codes.InvalidArgument

	// CodeDeadlineExceeded 表示操作在完成前过期。对于改变系统状态的操作,即使操作成功完成,也可能会返回此错误。
	// 例如,来自服务器的成功响应可能已延迟足够长的时间以使截止日期到期
	CodeDeadlineExceeded = codes.DeadlineExceeded

	// CodeNotFound 表示未找到某些请求的实体(例如文件或目录)
	CodeNotFound = codes.NotFound

	// CodeAlreadyExists 表示创建实体的尝试失败,因为实体已经存在
	CodeAlreadyExists = codes.AlreadyExists

	// CodePermissionDenied 表示调用者没有执行指定操作的权限
	CodePermissionDenied = codes.PermissionDenied

	// CodeResourceExhausted 表示某些资源已用尽,可能是每个用户的配额,或者可能是整个文件系统空间不足
	CodeResourceExhausted = codes.ResourceExhausted

	// CodeFailedPrecondition 操作被拒绝,因为系统未处于操作执行所需的状态。
	// 例如,要删除的目录可能是非空的,rmdir 操作应用于非目录等
	CodeFailedPrecondition = codes.FailedPrecondition

	// CodeAborted 操作已取消,通常是由于并发问题,如排序器检查失败、事务中止
	CodeAborted = codes.Aborted

	// CodeOutRange 超出范围的操作
	CodeOutRange = codes.OutOfRange

	// CodeUnimplemented 未实现或不支持的操作
	CodeUnimplemented = codes.Unimplemented

	// CodeInternal 系统内部错误
	CodeInternal = codes.Internal

	// CodeUnavailable 表示该服务当前不可用。这很可能是一种瞬态情况,可以通过回退重试来纠正。
	// 请注意,重试非幂等操作是不安全的
	CodeUnavailable = codes.Unavailable

	// CodeDataLoss 表示不可恢复的数据丢失或损坏
	CodeDataLoss = codes.DataLoss

	// CodeUnauthenticated 表示请求没有用于操作的有效身份验证凭据
	CodeUnauthenticated = codes.Unauthenticated
)

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 BigCamelByChar added in v2.0.9

func BigCamelByChar(str string, char byte) string

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 Bytes2Int16 added in v2.0.9

func Bytes2Int16(data []byte) int16

Bytes2Int16 字节切片转换为int16

func Bytes2Int32 added in v2.0.9

func Bytes2Int32(data []byte) int32

Bytes2Int32 字节切片转换为int32

func Bytes2Int64

func Bytes2Int64(data []byte) int64

Bytes2Int64 字节切片转换为int64

func Bytes2Int8 added in v2.0.9

func Bytes2Int8(data []byte) int8

Bytes2Int8 字节切片转换为int8

func Bytes2JpgBytes added in v2.0.9

func Bytes2JpgBytes(input []byte, quality int) ([]byte, error)

func Bytes2String

func Bytes2String(data []byte) string

Bytes2String 字节切片转换为字符串

func Bytes2Uint16 added in v2.0.9

func Bytes2Uint16(data []byte) uint16

Bytes2Uint16 字节切片转换为uint16

func Bytes2Uint32

func Bytes2Uint32(data []byte) uint32

Bytes2Uint32 字节切片转换为uint32

func Bytes2Uint64

func Bytes2Uint64(data []byte) uint64

Bytes2Uint64 字节切片转换为uint64

func Bytes2Uint8 added in v2.0.9

func Bytes2Uint8(data []byte) uint8

Bytes2Uint8 字节切片转换为uint8

func Bytes2WebpBytes added in v2.0.9

func Bytes2WebpBytes(input []byte, quality float32) ([]byte, error)

func Ceil added in v2.0.12

func Ceil[V kind.Number](value float64) V

func CropThumbnailImage added in v2.0.9

func CropThumbnailImage(img image.Image, width, height int) *image.RGBA

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 FiveMinuteAxis added in v2.0.6

func FiveMinuteAxis() []string

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 Image2Webp added in v2.0.9

func Image2Webp(in, out string, quality float32) error

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 Markdown2Html added in v2.0.9

func Markdown2Html(md []byte) []byte

func Markdown2HtmlWithOption added in v2.0.9

func Markdown2HtmlWithOption(md []byte, opts ...blackfriday.Option) []byte

func Md5

func Md5(data []byte) string

Md5 Md5算法

func MinuteAxis added in v2.0.6

func MinuteAxis() []string

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 SmallCamelByChar added in v2.0.9

func SmallCamelByChar(str string, char 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