filter

package module
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2020 License: BSD-3-Clause Imports: 12 Imported by: 1

README

filter

golang的数据过滤包,由 数据输入、格式化、校验、输出 几个部份组成。

  • 每个步骤都可以自定义错误消息
  • 过滤结果可以自动赋值到变量
  • 支持批量操作,合并错误处理代码
  • 可将过滤规则封装成函数,便于复用

github.com/dxvgef/filter/v2

示例

请参考example_test.go的单元测试代码,如需其它帮助请在Issues里提出。

函数列表

输入
  • String() 输入字符串类型的数据
格式化
  • Trim() 去除前后空格
  • RemoveSpace 去除所有空格
  • ReplaceAll 替换所有
  • ToUpper 字母转为大写
  • ToLower 字母转为小写
  • SnakeCaseToCamelCase 蛇形转驼峰: hello_world => helloWorld
  • SnakeCaseToPascalCase 蛇形转帕斯卡: hello_world => HelloWorld
  • CamelCaseToSnakeCase 驼峰(含帕斯卡)转蛇形 helloWorld/HelloWorld => hello_world
  • HTMLEscape 编码成HTML中显示的字符
  • HTMLUnescape HTMLEscape的解码函数
  • URLPathEscape 编码成能作为URL路径传输的字符
  • URLPathUnescape URLPathEscape的解码函数
  • URLQueryEscape 编码成能作为URL查询参数传输的字符
  • URLQueryUnescape URLQueryEscape的解码函数
  • Base64StdEncode Base64 std 编码
  • Base64StdDecode Base64 std 解码
  • Base64RawStdEncode Base64 raw std 编码
  • Base64RawStdDecode Base64 raw std 解码
  • Base64URLEncode Base64 URL 编码
  • Base64URLDecode Base64 URL 解码
  • Base64RawURLEncode Base64 raw URL 编码
  • Base64RawURLDecode Base64 raw URL 解码
校验
  • Require 参数不能为零值
  • Equal 匹配两个字符串相等
  • MinLength 最小长度
  • MinUTF8Length UTF8编码最小长度
  • MaxLength 最大长度
  • MaxUTF8Length UTF8编码最大长度
  • MinInteger 最小整数值
  • MaxInteger 最大整数值
  • MinFloat 最小浮点值
  • MaxFloat 最大浮点值
  • IsBool 是布尔值
  • IsLower 是小写字母
  • IsUpper 是大写字母
  • IsLetter 是字母
  • IsDigit 是数字,不能包含有任何符号或其它字符
  • IsLowerOrDigit 是小写字母或数字
  • IsUpperOrDigit 是大写字母或数字
  • IsLetterOrDigit 是字母或数字
  • IsChinese 是汉字
  • IsMail 是电邮地址
  • IsIP 是IPv4/v6地址
  • IsTCPAddr 是IP:Port格式
  • IsMAC 是MAC地址
  • IsJSON 是有效的JSON格式
  • IsChinaTel 是中国大陆地区固定电话号码
  • IsChinaMobile 是中国大陆地区手机号码
  • IsChinaIDNumber 是中国大陆地区身份证号码
  • IsSQLObject 是SQL对象名(库、表、字段)
  • IsSQLObjects 是SQL对象名集合
  • IsUUID 是UUID格式
  • IsURL 是URL格式
  • HasLetter 必须包含字母
  • HasLower 必须包含小写字母
  • HasUpper 必须包含大写字母
  • HasDigit 必须包含数字
  • HasSymbol 必须包含符号
  • HasPrefix 必须包含指定的前缀字符串
  • HasSuffix 必须包含指定的后缀字符串
  • HasString 必须包含指定的字符串
  • EnumString 仅允许[]string中的值
  • EnumInt 仅允许[]int中的值
  • EnumInt32 仅允许[]int32中的值
  • EnumInt64 仅允许[]int64中的值
  • EnumFloat32 仅允许[]float32中的值
  • EnumFloat64 仅允许[]float64中的值
  • EnumSliceString 将数据转为[]string,并检查其元素是否存在于指定的[]string中
  • EnumSliceInt 将数据转为[]int,并检查其元素是否存在于指定的[]int中
  • DenyString 阻止[]string中的值
  • DenyInt 阻止[]int中的值
  • DenyInt32 阻止[]int32中的值
  • DenyInt64 阻止[]int64中的值
  • DenyFloat32 阻止[]float32中的值
  • DenyFloat64 阻止[]float64中的值
输出
类型转换
  • String 转为string类型
  • DefaultString 转为string类型,出错则返回默认值
  • SliceString 转为[]string类型
  • DefaultSliceString 转为[]string类型,出错则返回默认值
  • Int 转为int类型
  • DefaultInt 转为int类型,出错则返回默认值
  • SliceInt 转为[]int类型
  • DefaultSliceInt 转为[]int类型,出错则返回默认值
  • Int8 转为int8类型
  • DefaultInt8 转为int8类型,出错则返回默认值
  • SliceInt8 转为[]int8类型
  • DefaultSliceInt8 转为[]int8类型,出错则返回默认值
  • Int16 转为int16类型
  • DefaultInt16 转为int16类型,出错则返回默认值
  • SliceInt16 转为[]int16类型
  • DefaultSliceInt16 转为[]int16类型,出错则返回默认值
  • Int32 转为int32类型
  • DefaultInt32 转为int32类型,出错则返回默认值
  • SliceInt32 转为[]int32类型
  • DefaultSliceInt32 转为[]int32类型,出错则返回默认值
  • Int64 转为int64类型
  • DefaultInt64 转为int64类型,出错则返回默认值
  • SliceInt64 转为[]int64类型
  • DefaultSliceInt64 转为[]int64类型,出错则返回默认值
  • Uint 转为uint类型
  • DefaultUint 转为uint类型,出错则返回默认值
  • SliceUint 转为[]uint类型
  • DefaultSliceUint 转为[]uint类型,出错则返回默认值
  • Uint8 转为uint8类型
  • DefaultUint8 转为uint8类型,出错则返回默认值
  • SliceUint8 转为[]uint8类型
  • DefaultSliceUint8 转为[]uint8类型,出错则返回默认值
  • Uint16 转为uint16类型
  • DefaultUint16 转为uint16类型,出错则返回默认值
  • SliceUint16 转为[]uint16类型
  • DefaultSliceUint16 转为[]uint16类型,出错则返回默认值
  • Uint32 转为uint32类型
  • DefaultUint32 转为uint32类型,出错则返回默认值
  • SliceUint32 转为[]uint32类型
  • DefaultSliceUint32 转为[]uint32类型,出错则返回默认值
  • Uint64 转为uint64类型
  • DefaultUint64 转为uint64类型,出错则返回默认值
  • SliceUint64 转为[]uint64类型
  • DefaultSliceUint64 转为[]uint64类型,出错则返回默认值
  • Float32 转为float32类型
  • DefaultFloat32 转为float32类型,出错则返回默认值
  • SliceFloat32 转为[]float32类型
  • DefaultSliceFloat32 转为[]float32类型,出错则返回默认值
  • Float64 转为float64类型
  • DefaultFloat64 转为float64类型,出错则返回默认值
  • SliceFloat64 转为[]float64类型
  • DefaultSliceFloat64 转为[]float64类型,出错则返回默认值
  • Bool 转为bool类型
  • DefaultBool 转为bool类型,出错则返回默认值
赋值
  • Set 将过滤结果赋值到普通变量
  • SetSlice 将过滤结果赋值到切片变量
结果
  • Error`` 过滤结果,返回error`类型

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultErrorText = "数据处理失败"

默认的错误文本

Functions

func Batch

func Batch(errs ...error) error

批处理

Types

type Str

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

func (*Str) Base64RawStdDecode

func (self *Str) Base64RawStdDecode(customError ...string) StrType

base64 RawStd解码

func (*Str) Base64RawStdEncode

func (self *Str) Base64RawStdEncode() StrType

base64 RawStd编码

func (*Str) Base64RawURLDecode

func (self *Str) Base64RawURLDecode(customError ...string) StrType

base64 RawURL解码

func (*Str) Base64RawURLEncode

func (self *Str) Base64RawURLEncode() StrType

base64 RawURL编码

func (*Str) Base64StdDecode

func (self *Str) Base64StdDecode(customError ...string) StrType

base64 std解码

func (*Str) Base64StdEncode

func (self *Str) Base64StdEncode() StrType

base64 std编码

func (*Str) Base64URLDecode

func (self *Str) Base64URLDecode(customError ...string) StrType

base64 URL解码

func (*Str) Base64URLEncode

func (self *Str) Base64URLEncode() StrType

base64 URL编码

func (*Str) Bool

func (self *Str) Bool() (bool, error)

Bool 转为bool类型

func (*Str) CamelCaseToSnakeCase

func (self *Str) CamelCaseToSnakeCase() StrType

CamelCaseToSnakeCase 驼峰(含帕斯卡)转蛇形 helloWorld/HelloWorld => hello_world

func (*Str) DefaultBool

func (self *Str) DefaultBool(def bool) bool

DefaultBool 转为bool类型,如果出错则只返回默认值

func (*Str) DefaultFloat32

func (self *Str) DefaultFloat32(def float32) float32

DefaultFloat32 转为float32类型,如果出错则只返回默认值

func (*Str) DefaultFloat64

func (self *Str) DefaultFloat64(def float64) float64

DefaultFloat64 转为float64类型,如果出错则只返回默认值

func (*Str) DefaultInt

func (self *Str) DefaultInt(def int) int

DefaultInt 转为int类型,如果出错则只返回默认值

func (*Str) DefaultInt16

func (self *Str) DefaultInt16(def int16) int16

DefaultInt16 转为int16类型,如果出错则只返回默认值

func (*Str) DefaultInt32

func (self *Str) DefaultInt32(def int32) int32

DefaultInt32 转为int32类型,如果出错则只返回默认值

func (*Str) DefaultInt64

func (self *Str) DefaultInt64(def int64) int64

DefaultInt64 转为int64类型,如果出错则只返回默认值

func (*Str) DefaultInt8

func (self *Str) DefaultInt8(def int8) int8

DefaultInt8 转为int8类型,如果出错则只返回默认值

func (*Str) DefaultSliceBool

func (self *Str) DefaultSliceBool(sep string, def []bool) []bool

DefaultSliceBool 转为[]bool类型

func (*Str) DefaultSliceFloat32

func (self *Str) DefaultSliceFloat32(sep string, def []float32) []float32

DefaultSliceFloat32 转为[]float32类型

func (*Str) DefaultSliceFloat64

func (self *Str) DefaultSliceFloat64(sep string, def []float64) []float64

DefaultSliceFloat64 转为[]float64类型

func (*Str) DefaultSliceInt

func (self *Str) DefaultSliceInt(sep string, def []int) []int

DefaultSliceInt 转为[]int类型,出错则返回传入的默认值

func (*Str) DefaultSliceInt16

func (self *Str) DefaultSliceInt16(sep string, def []int16) []int16

DefaultSliceInt16 转为[]int16类型

func (*Str) DefaultSliceInt32

func (self *Str) DefaultSliceInt32(sep string, def []int32) []int32

DefaultSliceInt32 转为[]int8类型

func (*Str) DefaultSliceInt64

func (self *Str) DefaultSliceInt64(sep string, def []int64) []int64

DefaultSliceInt64 转为[]int64类型,如果出错则只返回默认值

func (*Str) DefaultSliceInt8

func (self *Str) DefaultSliceInt8(sep string, def []int8) []int8

DefaultSliceInt8 转为[]int8类型,如果出错则只返回默认值

func (*Str) DefaultSliceString

func (self *Str) DefaultSliceString(sep string, def []string) []string

DefaultSliceString 使用SetSeparator()设置的分隔符拆分成[]string类型,如果出错则只返回默认值

func (*Str) DefaultSliceUint

func (self *Str) DefaultSliceUint(sep string, def []uint) []uint

DefaultSliceInt 转为[]int类型,出错则返回传入的默认值

func (*Str) DefaultSliceUint16

func (self *Str) DefaultSliceUint16(sep string, def []uint16) []uint16

DefaultSliceUint16 转为[]uint16类型

func (*Str) DefaultSliceUint32

func (self *Str) DefaultSliceUint32(sep string, def []uint32) []uint32

DefaultSliceUint32 转为[]uint8类型

func (*Str) DefaultSliceUint64

func (self *Str) DefaultSliceUint64(sep string, def []uint64) []uint64

DefaultSliceUint64 转为[]uint64类型,如果出错则只返回默认值

func (*Str) DefaultSliceUint8

func (self *Str) DefaultSliceUint8(sep string, def []uint8) []uint8

DefaultSliceUint8 转为[]uint8类型,如果出错则只返回默认值

func (*Str) DefaultString

func (self *Str) DefaultString(def string) string

DefaultString 转为string类型,如果出错则只返回默认值

func (*Str) DefaultUint

func (self *Str) DefaultUint(def uint) uint

DefaultUint 转为uint类型,如果出错则只返回默认值

func (*Str) DefaultUint16

func (self *Str) DefaultUint16(def uint16) uint16

DefaultUint16 转为uint16类型,如果出错则只返回默认值

func (*Str) DefaultUint32

func (self *Str) DefaultUint32(def uint32) uint32

DefaultUint32 转为uint32类型,如果出错则只返回默认值

func (*Str) DefaultUint64

func (self *Str) DefaultUint64(def uint64) uint64

DefaultUint64 转为uint64类型,如果出错则只返回默认值

func (*Str) DefaultUint8

func (self *Str) DefaultUint8(def uint8) uint8

DefaultUint8 转为uint8类型,如果出错则只返回默认值

func (*Str) DenyFloat32

func (self *Str) DenyFloat32(f []float32, customError ...string) StrType

DenyFloat32 阻止[]float32中的值

func (*Str) DenyFloat64

func (self *Str) DenyFloat64(f []float64, customError ...string) StrType

DenyFloats64 阻止[]float64中的值

func (*Str) DenyInt

func (self *Str) DenyInt(i []int, customError ...string) StrType

DenyInt 阻止[]int中的值

func (*Str) DenyInt16

func (self *Str) DenyInt16(i []int16, customError ...string) StrType

DenyInt16 阻止[]int16中的值

func (*Str) DenyInt32

func (self *Str) DenyInt32(i []int32, customError ...string) StrType

DenyInt32 阻止[]int32中的值

func (*Str) DenyInt64

func (self *Str) DenyInt64(i []int64, customError ...string) StrType

DenyInt64 阻止[]int64中的值

func (*Str) DenyInt8

func (self *Str) DenyInt8(i []int8, customError ...string) StrType

DenyInt8 阻止[]int8中的值

func (*Str) DenyString

func (self *Str) DenyString(slice []string, customError ...string) StrType

DenyString 阻止[]string中的值

func (*Str) EnumFloat32

func (self *Str) EnumFloat32(f []float32, customError ...string) StrType

EnumFloat32 仅允许[]float32中的值

func (*Str) EnumFloat64

func (self *Str) EnumFloat64(f []float64, customError ...string) StrType

EnumFloat64 仅允许[]float64中的值

func (*Str) EnumInt

func (self *Str) EnumInt(i []int, customError ...string) StrType

EnumInt 仅允许[]int中的值

func (*Str) EnumInt16

func (self *Str) EnumInt16(i []int16, customError ...string) StrType

EnumInt16 仅允许[]int16中的值

func (*Str) EnumInt32

func (self *Str) EnumInt32(i []int32, customError ...string) StrType

EnumInt32 仅允许[]int32中的值

func (*Str) EnumInt64

func (self *Str) EnumInt64(i []int64, customError ...string) StrType

EnumInt64 仅允许[]int64中的值

func (*Str) EnumInt8

func (self *Str) EnumInt8(i []int8, customError ...string) StrType

EnumInt8 仅允许[]int8中的值

func (*Str) EnumSliceInt

func (self *Str) EnumSliceInt(sep string, slice []int, customError ...string) StrType

EnumSliceInt 检查[]string中的元素,仅允许指潘秉衡[]int中的值

func (*Str) EnumSliceString

func (self *Str) EnumSliceString(sep string, slice []string, customError ...string) StrType

EnumSliceString 检查[]string中的元素,仅允许指定[]string中的值

func (*Str) EnumString

func (self *Str) EnumString(slice []string, customError ...string) StrType

EnumString 仅允许[]string中的值

func (*Str) Equal

func (self *Str) Equal(str string, customError ...string) StrType

Equal 与指定的字符串相等

func (*Str) Error

func (self *Str) Error() error

获得错误信息

func (*Str) Float32

func (self *Str) Float32() (float32, error)

Float32 转为float32类型

func (*Str) Float64

func (self *Str) Float64() (float64, error)

Float64 转为float64类型

func (*Str) HTMLEscape

func (self *Str) HTMLEscape() StrType

html.EscapeString

func (*Str) HTMLUnescape

func (self *Str) HTMLUnescape() StrType

html.UnescapeString

func (*Str) HasDigit

func (self *Str) HasDigit(customError ...string) StrType

必须包含数字

func (*Str) HasLetter

func (self *Str) HasLetter(customError ...string) StrType

必须包含字母(不区分大小写)

func (*Str) HasLower

func (self *Str) HasLower(customError ...string) StrType

必须包含小写字母

func (*Str) HasPrefix

func (self *Str) HasPrefix(sub string, customError ...string) StrType

必须包含指定的前缀字符串

func (*Str) HasString

func (self *Str) HasString(sub string, customError ...string) StrType

必须包含指定的字符串

func (*Str) HasSuffix

func (self *Str) HasSuffix(sub string, customError ...string) StrType

必须包含指定的后缀字符串

func (*Str) HasSymbol

func (self *Str) HasSymbol(customError ...string) StrType

必须包含符号

func (*Str) HasUpper

func (self *Str) HasUpper(customError ...string) StrType

必须包含大写字母

func (*Str) Int

func (self *Str) Int() (int, error)

Int 转为int类型

func (*Str) Int16

func (self *Str) Int16() (int16, error)

Int16 转为int16类型

func (*Str) Int32

func (self *Str) Int32() (int32, error)

Int32 转为int32类型

func (*Str) Int64

func (self *Str) Int64() (int64, error)

Int64 转为int64类型

func (*Str) Int8

func (self *Str) Int8() (int8, error)

Int8 转为int8类型

func (*Str) IsBool

func (self *Str) IsBool(customError ...string) StrType

IsBool 布尔值

func (*Str) IsChinaIDNumber

func (self *Str) IsChinaIDNumber(customError ...string) StrType

IsChinaIDNumber 中国身份证号码

func (*Str) IsChinaMobile

func (self *Str) IsChinaMobile(customError ...string) StrType

nolint:gocyclo IsChinaMobile 中国手机号码

func (*Str) IsChinaTel

func (self *Str) IsChinaTel(customError ...string) StrType

IsChinaTel 中国固定电话号码

func (*Str) IsChinese

func (self *Str) IsChinese(customError ...string) StrType

IsChinese 汉字

func (*Str) IsDigit

func (self *Str) IsDigit(customError ...string) StrType

IsDigit 无符号数字

func (*Str) IsIP

func (self *Str) IsIP(customError ...string) StrType

IsIP IPv4/v6地址

func (*Str) IsJSON

func (self *Str) IsJSON(customError ...string) StrType

IsJSON JSON格式

func (*Str) IsLetter

func (self *Str) IsLetter(customError ...string) StrType

IsLetter 大小写字母

func (*Str) IsLetterOrDigit

func (self *Str) IsLetterOrDigit(customError ...string) StrType

IsLetterOrDigit 字母或数字

func (*Str) IsLower

func (self *Str) IsLower(customError ...string) StrType

IsLower 小写字母

func (*Str) IsLowerOrDigit

func (self *Str) IsLowerOrDigit(customError ...string) StrType

IsLowerOrDigit 小写字母或数字

func (*Str) IsMAC

func (self *Str) IsMAC(customError ...string) StrType

IsMAC MAC地址

func (*Str) IsMail

func (self *Str) IsMail(customError ...string) StrType

IsMail 电邮地址

func (*Str) IsSQLObject

func (self *Str) IsSQLObject(customError ...string) StrType

IsSQLObject SQL对象(库名、表名、字段名)

func (*Str) IsSQLObjects

func (self *Str) IsSQLObjects(sep string, customError ...string) StrType

IsSQLObjects SQL对象集合(库名、表名、字段名)

func (*Str) IsTCPAddr

func (self *Str) IsTCPAddr(customError ...string) StrType

IsTCPAddr IP:Port

func (*Str) IsURL

func (self *Str) IsURL(customError ...string) StrType

IsURL 是有效的URL

func (*Str) IsUUID

func (self *Str) IsUUID(customError ...string) StrType

IsUUID UUID格式

func (*Str) IsUpper

func (self *Str) IsUpper(customError ...string) StrType

IsUpper 大写字母

func (*Str) IsUpperOrDigit

func (self *Str) IsUpperOrDigit(customError ...string) StrType

IsUpperOrDigit 大写字母或数字

func (*Str) JoinByte

func (self *Str) JoinByte(values ...byte) StrType

拼接byte

func (*Str) JoinBytes

func (self *Str) JoinBytes(values ...[]byte) StrType

拼接bytes

func (*Str) JoinRune

func (self *Str) JoinRune(values ...rune) StrType

拼接rune

func (*Str) JoinStr

func (self *Str) JoinStr(values ...string) StrType

拼接string

func (*Str) MaxFloat

func (self *Str) MaxFloat(max float64, customError ...string) StrType

MinFloat 最大浮点值

func (*Str) MaxInteger

func (self *Str) MaxInteger(max int64, customError ...string) StrType

MinInteger 最大整数值

func (*Str) MaxLength

func (self *Str) MaxLength(max int, customError ...string) StrType

MaxLength 最大长度

func (*Str) MaxUTF8Length

func (self *Str) MaxUTF8Length(max int, customError ...string) StrType

MaxUTF8Length UTF8编码最大长度

func (*Str) MinFloat

func (self *Str) MinFloat(min float64, customError ...string) StrType

MinFloat 最小浮点值

func (*Str) MinInteger

func (self *Str) MinInteger(min int64, customError ...string) StrType

MinInteger 最小整数值

func (*Str) MinLength

func (self *Str) MinLength(min int, customError ...string) StrType

MinLength 最小长度

func (*Str) MinUTF8Length

func (self *Str) MinUTF8Length(min int, customError ...string) StrType

MinUTF8Length UTF8编码最小长度

func (*Str) RemoveSpace

func (self *Str) RemoveSpace() StrType

删除所有空格

func (*Str) Require

func (self *Str) Require(customError ...string) StrType

必须有值(不能为零值)

func (*Str) Set

func (self *Str) Set(target interface{}, customError ...string) error

赋值到普通对象

func (*Str) SetSlice

func (self *Str) SetSlice(target interface{}, sep string, customError ...string) error

func (*Str) SliceBool

func (self *Str) SliceBool(sep string) (result []bool, err error)

SliceBool 转为[]bool类型

func (*Str) SliceFloat32

func (self *Str) SliceFloat32(sep string) (result []float32, err error)

SliceFloat32 转为[]float32类型

func (*Str) SliceFloat64

func (self *Str) SliceFloat64(sep string) (result []float64, err error)

SliceFloat64 转为[]float64类型

func (*Str) SliceInt

func (self *Str) SliceInt(sep string) (result []int, err error)

SliceInt 转为[]int类型

func (*Str) SliceInt16

func (self *Str) SliceInt16(sep string) (result []int16, err error)

SliceInt16 转为[]int16类型

func (*Str) SliceInt32

func (self *Str) SliceInt32(sep string) (result []int32, err error)

SliceInt32 转为[]int32类型

func (*Str) SliceInt64

func (self *Str) SliceInt64(sep string) (result []int64, err error)

SliceInt64 转为[]int64类型

func (*Str) SliceInt8

func (self *Str) SliceInt8(sep string) (result []int8, err error)

SliceInt8 转为[]int8类型

func (*Str) SliceString

func (self *Str) SliceString(sep string) ([]string, error)

SliceString 使用SetSeparator()设置的分隔符拆分成[]string类型

func (*Str) SliceUint

func (self *Str) SliceUint(sep string) (result []uint, err error)

SliceInt 转为[]int类型

func (*Str) SliceUint16

func (self *Str) SliceUint16(sep string) (result []uint16, err error)

SliceUint16 转为[]uint16类型

func (*Str) SliceUint32

func (self *Str) SliceUint32(sep string) (result []uint32, err error)

SliceUint32 转为[]uint32类型

func (*Str) SliceUint64

func (self *Str) SliceUint64(sep string) (result []uint64, err error)

SliceUint64 转为[]uint64类型

func (*Str) SliceUint8

func (self *Str) SliceUint8(sep string) (result []uint8, err error)

SliceUint8 转为[]int8类型

func (*Str) SnakeCaseToCamelCase

func (self *Str) SnakeCaseToCamelCase() StrType

SnakeCaseToCamelCase 蛇形转驼峰: hello_world => helloWorld

func (*Str) SnakeCaseToPascalCase

func (self *Str) SnakeCaseToPascalCase() StrType

SnakeCaseToPascalCase 蛇形转帕斯卡: hello_world => HelloWorld

func (*Str) String

func (self *Str) String() (string, error)

String 转为string类型

func (*Str) ToLower

func (self *Str) ToLower() StrType

字母转为小写

func (*Str) ToUpper

func (self *Str) ToUpper() StrType

字母转为大写

func (*Str) Trim

func (self *Str) Trim(sub string) StrType

删除左右的指定字符串

func (*Str) TrimLeft

func (self *Str) TrimLeft(sub string) StrType

删除左边的指定字符串

func (*Str) TrimPrefix

func (self *Str) TrimPrefix(sub string) StrType

删除指定的前缀字符串

func (*Str) TrimRight

func (self *Str) TrimRight(sub string) StrType

删除右边的指定字符串

func (*Str) TrimSpace

func (self *Str) TrimSpace() StrType

删除左右的空格

func (*Str) TrimSuffix

func (self *Str) TrimSuffix(sub string) StrType

删除指定的后缀字符串

func (*Str) URLPathEscape

func (self *Str) URLPathEscape() StrType

与url.PathEscape相同

func (*Str) URLPathUnescape

func (self *Str) URLPathUnescape(customError ...string) StrType

url.PathUnescape

func (*Str) URLQueryEscape

func (self *Str) URLQueryEscape() StrType

与url.QueryEscape相同

func (*Str) URLQueryUnescape

func (self *Str) URLQueryUnescape(customError ...string) StrType

与url.QueryUnescape相同

func (*Str) Uint

func (self *Str) Uint() (uint, error)

Uint 转为uint类型

func (*Str) Uint16

func (self *Str) Uint16() (uint16, error)

Uint16 转为uint16类型

func (*Str) Uint32

func (self *Str) Uint32() (uint32, error)

Uint32 转为uint32类型

func (*Str) Uint64

func (self *Str) Uint64() (uint64, error)

Uint64 转为uint64类型

func (*Str) Uint8

func (self *Str) Uint8() (uint8, error)

Uint8 转为uint8类型

type StrType

type StrType interface {
	// 清理
	Trim(string) StrType
	TrimSpace() StrType
	TrimLeft(string) StrType
	TrimRight(string) StrType
	TrimPrefix(string) StrType
	TrimSuffix(string) StrType
	RemoveSpace() StrType
	ToUpper() StrType
	ToLower() StrType
	SnakeCaseToCamelCase() StrType
	SnakeCaseToPascalCase() StrType
	CamelCaseToSnakeCase() StrType
	Base64StdEncode() StrType
	Base64StdDecode(...string) StrType
	Base64RawStdEncode() StrType
	Base64RawStdDecode(...string) StrType
	Base64URLEncode() StrType
	Base64URLDecode(...string) StrType
	Base64RawURLEncode() StrType
	Base64RawURLDecode(...string) StrType
	HTMLUnescape() StrType
	HTMLEscape() StrType
	URLPathUnescape(...string) StrType
	URLPathEscape() StrType
	URLQueryUnescape(...string) StrType
	URLQueryEscape() StrType
	JoinStr(...string) StrType
	JoinBytes(...[]byte) StrType
	JoinByte(...byte) StrType
	JoinRune(...rune) StrType

	// 校验
	Require(...string) StrType
	Equal(string, ...string) StrType

	HasLetter(...string) StrType
	HasLower(...string) StrType
	HasUpper(...string) StrType
	HasDigit(...string) StrType
	HasSymbol(...string) StrType
	HasString(string, ...string) StrType
	HasPrefix(string, ...string) StrType
	HasSuffix(string, ...string) StrType

	IsBool(...string) StrType
	IsLower(...string) StrType
	IsUpper(...string) StrType
	IsLetter(...string) StrType
	IsDigit(...string) StrType
	IsLowerOrDigit(...string) StrType
	IsUpperOrDigit(...string) StrType
	IsLetterOrDigit(...string) StrType
	IsChinese(...string) StrType
	IsChinaTel(...string) StrType
	IsMail(...string) StrType
	IsIP(...string) StrType
	IsTCPAddr(...string) StrType
	IsMAC(...string) StrType
	IsJSON(...string) StrType
	IsChinaIDNumber(...string) StrType
	IsChinaMobile(...string) StrType
	IsSQLObject(...string) StrType
	IsSQLObjects(string, ...string) StrType
	IsURL(...string) StrType
	IsUUID(...string) StrType

	MinLength(int, ...string) StrType
	MinUTF8Length(int, ...string) StrType
	MaxLength(int, ...string) StrType
	MaxUTF8Length(int, ...string) StrType

	MinInteger(int64, ...string) StrType
	MaxInteger(int64, ...string) StrType
	MinFloat(float64, ...string) StrType
	MaxFloat(float64, ...string) StrType

	EnumString([]string, ...string) StrType
	EnumInt([]int, ...string) StrType
	EnumInt8([]int8, ...string) StrType
	EnumInt16([]int16, ...string) StrType
	EnumInt32([]int32, ...string) StrType
	EnumInt64([]int64, ...string) StrType
	EnumFloat32([]float32, ...string) StrType
	EnumFloat64([]float64, ...string) StrType

	EnumSliceString(string, []string, ...string) StrType
	EnumSliceInt(string, []int, ...string) StrType

	DenyString([]string, ...string) StrType
	DenyInt([]int, ...string) StrType
	DenyInt8([]int8, ...string) StrType
	DenyInt16([]int16, ...string) StrType
	DenyInt32([]int32, ...string) StrType
	DenyInt64([]int64, ...string) StrType
	DenyFloat32([]float32, ...string) StrType
	DenyFloat64([]float64, ...string) StrType

	// 输出
	String() (string, error)
	DefaultString(string) string
	SliceString(string) ([]string, error)
	DefaultSliceString(string, []string) []string
	Int() (int, error)
	DefaultInt(int) int
	SliceInt(string) ([]int, error)
	DefaultSliceInt(string, []int) []int
	Uint() (uint, error)
	DefaultUint(uint) uint
	SliceUint(string) ([]uint, error)
	DefaultSliceUint(string, []uint) []uint
	Int8() (int8, error)
	DefaultInt8(int8) int8
	SliceInt8(string) ([]int8, error)
	DefaultSliceInt8(string, []int8) []int8
	Uint8() (uint8, error)
	DefaultUint8(uint8) uint8
	SliceUint8(string) ([]uint8, error)
	DefaultSliceUint8(string, []uint8) []uint8
	Int16() (int16, error)
	DefaultInt16(int16) int16
	SliceInt16(string) ([]int16, error)
	DefaultSliceInt16(string, []int16) []int16
	Uint16() (uint16, error)
	DefaultUint16(uint16) uint16
	SliceUint16(string) ([]uint16, error)
	DefaultSliceUint16(string, []uint16) []uint16
	Int32() (int32, error)
	DefaultInt32(int32) int32
	SliceInt32(string) ([]int32, error)
	DefaultSliceInt32(string, []int32) []int32
	Uint32() (uint32, error)
	DefaultUint32(uint32) uint32
	SliceUint32(string) ([]uint32, error)
	DefaultSliceUint32(string, []uint32) []uint32
	Int64() (int64, error)
	DefaultInt64(int64) int64
	SliceInt64(string) ([]int64, error)
	DefaultSliceInt64(string, []int64) []int64
	Uint64() (uint64, error)
	DefaultUint64(uint64) uint64
	SliceUint64(string) ([]uint64, error)
	DefaultSliceUint64(string, []uint64) []uint64
	Float32() (float32, error)
	DefaultFloat32(float32) float32
	SliceFloat32(string) ([]float32, error)
	DefaultSliceFloat32(string, []float32) []float32
	Float64() (float64, error)
	DefaultFloat64(float64) float64
	SliceFloat64(string) ([]float64, error)
	DefaultSliceFloat64(string, []float64) []float64
	Bool() (bool, error)
	DefaultBool(bool) bool
	SliceBool(string) ([]bool, error)
	DefaultSliceBool(string, []bool) []bool

	// 赋值到普通变量
	Set(interface{}, ...string) error
	// 赋值到切片变量
	SetSlice(interface{}, string, ...string) error

	// 结果
	Error() error
}

func String

func String(value string, name ...string) StrType

输入字符串类型的值

Jump to

Keyboard shortcuts

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