Documentation
¶
Index ¶
- Variables
- func Bool[T any](value T) bool
- func BoolWith[T any](value T, defaulted bool) bool
- func Int[T any](value T) int
- func IntWith[T any](value T, defaulted int) int
- func IsNil[T any](v T) bool
- func MustBool[T any](value T) (bool, error)
- func MustInt[T any](value T) (int, error)
- func Ptr[T any](v T) *T
- func Rand[T number](min, max T) T
- func RandAlphanum(n int) string
- func RandSafeAlphanum(n int) string
- func SecureRand[T number](min, max T) (T, error)
- func SlicePtr[T any](s []T) []*T
- func SliceVal[T any](s []*T) []T
- func Val[T any](p *T) T
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func MustBool ¶
MustBool 将任意值转换为布尔值,如果无法转化则返回err 如果传入值是 boolean,直接强制转换返回; 如果传入值是 string,则按以下规则转换:
"true, yes, y" -> true "false, no, n, " -> false "" -> false "0.0···001 ... 1 ... ∞" -> true "-∞ ... -1 ... -0.1 ... 0" -> false "other word" -> ERROR
如果传入值是 数字,大于零返回 true,否则返回 false
0.0···001 ... 1 ... ∞ -> true -∞ ... -1 ... -0.1 ... 0 -> false
如果传入值是其他类型,则返回 ERROR
func MustInt ¶
MustInt 将任意值转换为整型 如果输入值是 数字,则直接转换; 如果输入值是 boolean,则 true 转为 1;false 转为 0; 如果输入值是 string,则按字符串转换规则 否则抛出 ERROR
func RandSafeAlphanum ¶
RandSafeAlphanum 生成固定长度的随机易辨识的字符串 适合用于验证码、密码等需要人工识别的场景
func SecureRand ¶
func SecureRand[T number](min, max T) (T, error)
SecureRand 生成 [min, max) 范围内的加密安全随机数
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.