utils

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Red color = iota
	Green
	BrightBlue
	Magenta // 紫色
	Cyan    // 青色
)

Variables

This section is empty.

Functions

func DeJSONalizeStr added in v0.31.0

func DeJSONalizeStr(s string, v any) error

DeJSONalizeStr 将 JSON 字符串解码到 v 指向的值中。 v 必须是非 nil 的指针,否则返回 error。

func DelayDo added in v0.20.0

func DelayDo(d time.Duration, fn func())

func DevLogError added in v0.38.0

func DevLogError(errMsg string)

func DevLogInfo added in v0.38.0

func DevLogInfo(infoMsg string)

func DevLogSuccess added in v0.38.0

func DevLogSuccess(successMsg string)

func GetNextColor added in v0.18.0

func GetNextColor() color

func Hold added in v0.23.0

func Hold()

func IsDev

func IsDev() bool

func IsDigits added in v0.20.0

func IsDigits(s string) bool

func IsNil added in v0.19.0

func IsNil[T any](v T) bool

IsNil returns true if v is a nil value for nilable kinds or an untyped nil interface.

func JSONalizeStr added in v0.31.0

func JSONalizeStr(v any) string

JSONalizeStr 尝试将任意对象编码为漂亮的 JSON 字符串;若 JSON 编码失败,则回退到 PrettyObjStr。

func LogMessage

func LogMessage(message string)

func PPrettyPrint added in v0.31.0

func PPrettyPrint(v any)

PPrettyPrint 使用 spew 打印任意对象(更接近 Python pprint)

func PPrint added in v0.21.0

func PPrint(obj interface{})

PPrint 格式化打印任意对象

func PrettyObjStr added in v0.31.0

func PrettyObjStr(v any) string

PrettyObjStr 返回对象的漂亮字符串表示(不打印,供日志/前端返回)

func PrintlnColor added in v0.18.0

func PrintlnColor(c color, text string)

PrintlnColor 输出彩色文字并换行

func RetryWork

func RetryWork(work func() (any, error), retryTimes int) (any, error)

RetryWork 执行工作函数,捕获panic或error并最多重试retryTimes次 work: 需要执行的工作函数 retryTimes: 最大重试次数(不包括首次执行)

func TimeoutWork added in v0.30.0

func TimeoutWork(work func() (any, error), timeout time.Duration) (any, error)

Types

type Number added in v0.34.0

type Number struct {
	// contains filtered or unexported fields
}

Number 模拟 TypeScript 的 number 类型,既可以表示整数也可以表示浮点数。 底层使用 float64 存储,这与 JS/TS 的实现机制一致。

func ParseNumber added in v0.34.0

func ParseNumber(raw string) (*Number, error)

ParseNumber 将字符串解析为 *Number。 它使用 strconv.ParseFloat,因此可以处理 "100" 和 "100.5" 两种情况。

func (*Number) Float added in v0.34.0

func (n *Number) Float() float64

Float 返回底层的 float64 值

func (*Number) Int added in v0.34.0

func (n *Number) Int() int

Int 返回数值的整数部分 (直接截断小数)

func (*Number) Int64 added in v0.34.0

func (n *Number) Int64() int64

Int64 返回 int64 类型的整数部分

func (*Number) IsInteger added in v0.34.0

func (n *Number) IsInteger() bool

IsInteger 判断该数值是否为一个整数(即没有小数部分) 例如 10.0 会返回 true, 10.5 会返回 false

Jump to

Keyboard shortcuts

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