Documentation
¶
Index ¶
- func Bool(v interface{}) bool
- func Cond(cond bool, trueVal interface{}, falseVal interface{}) interface{}
- func CopyStruct(src, dst interface{})
- func DeepCopy(v interface{}) interface{}
- func EmptyCond(v interface{}, elseVal interface{}) interface{}
- func Float32(v interface{}) float32
- func Float64(v interface{}) float64
- func Int(v interface{}) int
- func Int32(v interface{}) int32
- func Int64(v interface{}) int64
- func IsEmpty(v interface{}) bool
- func IsList(i interface{}) bool
- func IsMap(v interface{}) bool
- func IsNil(i interface{}) bool
- func NilCond(v interface{}, elseVal interface{}) interface{}
- func RandNumericString(len int) string
- func RandString(len int) string
- func RandStringSecure(len int) (string, error)
- func String(v interface{}) string
- func SubString(str string, start, end int) string
- func Uint(v interface{}) uint
- func Uint32(v interface{}) uint32
- func Uint64(v interface{}) uint64
- type KVPair
- type KVPairs
- func (p KVPairs) Add(k, v string)
- func (p KVPairs) Append(k, v string) KVPairs
- func (p KVPairs) EscapedString() string
- func (p KVPairs) FilterEmptyValueAndKeys(keys ...string) KVPairs
- func (p KVPairs) Len() int
- func (p KVPairs) Less(i, j int) bool
- func (p KVPairs) QuotedAndEscapedString() string
- func (p KVPairs) QuotedString() string
- func (p KVPairs) Reverse()
- func (p KVPairs) Sort()
- func (p KVPairs) String() string
- func (p KVPairs) Swap(i, j int)
- func (p KVPairs) ToMap() map[string]string
- func (p KVPairs) ToXML() string
- type M
- func (m M) Contains(k string) bool
- func (m M) DefaultGet(k string, dv interface{}) interface{}
- func (m M) DefaultGetBool(k string, b bool) bool
- func (m M) DefaultGetFloat64(k string, f float64) float64
- func (m M) DefaultGetInt(k string, i int) int
- func (m M) DefaultGetInt64(k string, i int64) int64
- func (m M) DefaultGetString(k, s string) string
- func (m M) DefaultGetUint(k string, i uint) uint
- func (m M) DefaultGetUint64(k string, i uint64) uint64
- func (m M) Del(k string)
- func (m M) ForceMerge(n M)
- func (m M) Get(k string) (interface{}, bool)
- func (m M) GetBool(k string) bool
- func (m M) GetByPath(path string) (interface{}, bool)
- func (m M) GetFloat32(k string) float32
- func (m M) GetFloat64(k string) float64
- func (m M) GetInt(k string) int
- func (m M) GetInt64(k string) int64
- func (m M) GetJson(k string) string
- func (m M) GetString(k string) string
- func (m M) GetUint(k string) uint
- func (m M) GetUint64(k string) uint64
- func (m M) IsArray(k string) bool
- func (m M) IsEmpty(k string) bool
- func (m M) Json() string
- func (m M) Keys() []string
- func (m M) MVal(k string) M
- func (m M) MValByPath(path string) (M, bool)
- func (m M) Map() map[string]interface{}
- func (m M) Merge(n M)
- func (m M) Pairs() KVPairs
- func (m M) SMVal(k string) []M
- func (m M) SMValByPath(path string) ([]M, bool)
- func (m M) SVal(k string) S
- func (m M) SValByPath(path string) (S, bool)
- func (m M) Size() int
- func (m M) UrlQuery() string
- func (m M) UrlValues() url.Values
- type S
- func (s S) Contains(v interface{}) bool
- func (s S) Extend(f func(interface{}) string) *XS
- func (s S) Filter()
- func (s S) Filtered() S
- func (s S) Float64() []float64
- func (s S) Int() []int
- func (s S) Int64() []int64
- func (s S) Interface() []interface{}
- func (s S) Json() string
- func (s *S) Load(v []byte) error
- func (s S) M() []M
- func (s S) Size() int
- func (s S) String() []string
- func (s S) Uint() []uint
- func (s S) Uint64() []uint64
- type Tree
- type TreeItem
- type XS
- func (xs *XS) Add(args ...interface{})
- func (xs *XS) Contains(v interface{}) bool
- func (xs *XS) Delete(arg interface{})
- func (xs *XS) Intersect(arrs ...S) *XS
- func (xs *XS) SAdd(args ...interface{})
- func (xs *XS) Size() int
- func (xs *XS) Slice() []interface{}
- func (xs *XS) Union(arrs ...S) *XS
- func (xs *XS) Unique() []interface{}
- func (xs *XS) UniqueFilter(f func(string) bool) []interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
func Bool(v interface{}) bool
Bool 将任意值转换成bool类型 注意:1. 当无法或者不支持转换时,此接口将返回false;
- 此接口应当只在明确数据内容只是需要类型转换时使用,不应当用于对未知值进行转换;
- 字符串会先按 strconv.ParseBool 解析(支持 "true"/"false"/"T"/"F"/"1"/"0" 等), 解析失败后再按数字处理,因此 Bool("true") 与 Bool("1") 均返回true。
func Cond ¶
func Cond(cond bool, trueVal interface{}, falseVal interface{}) interface{}
Cond 条件表达式,用于实现三元运算符的功能,if cond == true then trueVal else falseVal
func CopyStruct ¶
func CopyStruct(src, dst interface{})
CopyStruct 复制结构体 说明:将src中与dst同名的字段值复制到dst中,src和dst均支持结构体或结构体指针; 若src或dst为nil、非结构体、或目标字段不可写,则跳过对应字段而不会panic。
func DeepCopy ¶
func DeepCopy(v interface{}) interface{}
DeepCopy 深度复制一个值,处理嵌套的map、slice、指针和结构体 返回一个新的独立副本,修改副本不会影响原始值 注意:map类型统一返回 map[string]interface{}(key会被转换为string),此行为为兼容历史版本而保留
func EmptyCond ¶
func EmptyCond(v interface{}, elseVal interface{}) interface{}
EmptyCond 判断值v,如果为空(零值或者nil),则返回elseVal,否则返回v本身
func Float64 ¶
func Float64(v interface{}) float64
Float64 将任意值转换成float64类型 注意:1. 当无法或者不支持转换时,此接口将返回0值;
- 此接口应当只在明确数据内容只是需要类型转换时使用,不应当用于对未知值进行转换。
func Int64 ¶
func Int64(v interface{}) int64
Int64 将任意值转换成int64类型 注意:1. 当无法或者不支持转换时,此接口将返回0值;
- 此接口应当只在明确数据内容只是需要类型转换时使用,不应当用于对未知值进行转换。
func NilCond ¶
func NilCond(v interface{}, elseVal interface{}) interface{}
NilCond 判断值v,如果等于nil,则返回elseVal,否则返回v本身
func RandNumericString ¶
RandNumericString 生成一个只包含数字的随机字符串 说明:使用全局并发安全的随机源,同一秒内多次调用也会返回不同的结果
func RandString ¶
RandString 获取随机字符串(仅包含大写字母) 说明:使用全局并发安全的随机源,同一秒内多次调用也会返回不同的结果; 此方法不适用于生成密钥、令牌等安全敏感场景,安全敏感场景请使用 RandStringSecure
func RandStringSecure ¶
RandStringSecure 使用加密安全的随机源生成一个随机字符串 字符集为大写字母、小写字母与数字,适用于生成令牌、随机密钥等安全敏感场景
func String ¶
func String(v interface{}) string
String 将任意值转换成string类型 注意:1. 当无法或者不支持转换时,此接口将返回0值;
- 此接口应当只在明确数据内容只是需要类型转换时使用,不应当用于对未知值进行转换。
Types ¶
type KVPairs ¶
type KVPairs []KVPair
KVPairs 参数键值对列表
func (KVPairs) Add ¶
Add 添加键值对 注意:由于KVPairs是切片类型,且此方法使用值接收者,append的结果不会回写到调用方, 因此此方法实际上不会修改原列表(历史遗留缺陷,为保证兼容性保留)。 请使用 Append 方法,或直接使用 append(pairs, KVPair{K: k, V: v})。 Deprecated: 此方法无实际效果,请使用 Append。
func (KVPairs) EscapedString ¶
EscapedString 将所有元素按照“参数=urlencode(参数值)”的模式用“&”字符拼接成字符串
func (KVPairs) FilterEmptyValueAndKeys ¶
FilterEmptyValueAndKeys 去掉列表中值为空以及指定字段的值
func (KVPairs) QuotedAndEscapedString ¶
QuotedAndEscapedString 自定义值的处理方式
func (KVPairs) QuotedString ¶
QuotedString 将所有元素按照“参数="参数值"”的模式用“&”字符拼接成字符串
type M ¶
type M map[string]interface{}
M 常用的map类型
func (M) DefaultGet ¶
DefaultGet 获取配置项k的值,如果不存在则返回默认值
func (M) DefaultGetString ¶
DefaultGetString 获取指定K的值,如果K不存在,则返回默认值
func (M) GetByPath ¶
GetByPath 根据path获取值 path使用"."分隔,如 "a.b.c";路径中的每一级都必须是一个map,否则返回false 说明:此方法为只读操作,不会复制数据;历史实现每次调用都会深拷贝一份数据,性能较差
func (M) GetFloat32 ¶
func (M) GetFloat64 ¶
type S ¶
type S []interface{}
S 常用的slice类型
type TreeItem ¶
type TreeItem interface {
Key() string
ParentKey() string
AddChild(ti TreeItem)
GetChild(k string) (TreeItem, bool)
}
TreeItem 定义构成树的元素接口
type XS ¶
type XS struct {
// contains filtered or unexported fields
}
XS 扩展增强的slice对象
func (*XS) Delete ¶
func (xs *XS) Delete(arg interface{})
Delete 删除指定值的元素 说明:删除列表中所有key与被删除值相同的元素(key由创建XS时指定的keyFunc生成); 若元素不存在则不做任何操作。此方法为并发安全方法。
func (*XS) Intersect ¶
Intersect 计算给定切片与当前列表的交集 说明:返回同时存在于当前列表与所有给定切片中的元素(按key去重,保留当前列表中的顺序)。 若未传入任何切片,则返回当前列表去重后的结果。
func (*XS) Unique ¶
func (xs *XS) Unique() []interface{}
Unique 对列表元素去重 说明:返回结果按照元素首次加入的顺序排列,保证结果的稳定性
func (*XS) UniqueFilter ¶
UniqueFilter 对列表元素去重,并根据filter方法进行过滤 filter参数是一个字符串,此值是根据创建XS对象时指定的keyFunc得到的 说明:返回结果按照元素首次加入的顺序排列,保证结果的稳定性