types

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

json 相关处理 User: 青锋真人<[email protected]> Datetime: 2020/5/27 09:57

Package types 时间类型转换 User: 青锋真人<[email protected]> Datetime: 2020/2/8 11:30

Index

Constants

View Source
const (
	//URL相关选项
	URL_SCHEME_HTTP  = 1 //只允许http
	URL_SCHEME_HTTPS = 2 //只允许https
	URL_SCHEME_AUTO  = 4 //只允许自动判断协议

	//IP相关选项
	IP_V4 = 1 //只允许IPv4
	IP_V6 = 2 //只允许IPv6
)

Variables

This section is empty.

Functions

func AddSlashes

func AddSlashes(value interface{}) string

将slashesChars列表中的字符加上反斜杠进行转义

func Bytes2Str

func Bytes2Str(b []byte) string

以下方法更新 Go 1.20 and higher 版本的实现 Bytes2Str 零拷贝

func DateTimeString

func DateTimeString(args ...interface{}) string

DateTimeString 格式化显示时间 为空时,默认转换格式为 2020-02-08 11:28:01 只传一个参数,如果是字符串,则表示输出时间格式,时间为当前时间。如果是时间,则表示将该时间转换 2020-02-08 11:44:08 格式 传了两个参数,则第一个为输出格式,第二个为时间

func DeepFields

func DeepFields(ifaceType reflect.Type) []reflect.StructField

func IsChineseChar

func IsChineseChar(args ...interface{}) bool

检测是否是中文

func IsEmail

func IsEmail(value interface{}) bool

检测是否是email

func IsEmpty

func IsEmpty(value interface{}) bool

检测是否为空(值为""或nil时判定为空)

func IsFloat

func IsFloat(value interface{}) bool

检测是否是浮点数

func IsFloatStr added in v1.0.3

func IsFloatStr(str string) bool

IsFloatStr 检查是否为浮点型数字字符串

func IsIDCard

func IsIDCard(value string) bool

检测是否是身份证(18位),身份证可能有个X,所以必定是字符串

func IsIP

func IsIP(args ...interface{}) bool

检测是否是IP

func IsInArray

func IsInArray(value interface{}, arr []interface{}) bool

检测值是否在指定列表中,只支持数值和字符串检测

func IsInRange

func IsInRange(args ...interface{}) bool

检测值是否在指定区间中(包含min和max)

func IsInSizeRange

func IsInSizeRange(args ...interface{}) bool

检查内容是否在指定长度

func IsIntStr added in v1.0.3

func IsIntStr(str string) bool

IsIntStr 检查是否为整型数字字符串

func IsInteger

func IsInteger(value interface{}) bool

检测是否为整数,排除以0开头,例如"023"不算整数,支持负数

func IsMatch

func IsMatch(value interface{}, regex string) bool

利用正则进行检测

func IsMobilePhone

func IsMobilePhone(value interface{}) bool

检测是否是手机

func IsNumberStr added in v1.0.3

func IsNumberStr(str string) bool

IsNumberStr 检查是否为数字字符串

func IsPrivateIp

func IsPrivateIp(ip string) bool

检测是否是内网IP

func IsSecureString

func IsSecureString(value string) bool

检测是否是安全的字符串

func IsURL

func IsURL(args ...interface{}) bool

检测是否是URL格式数据

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal 默认的 json.Marshal 会转义 < > & 为 \u003c \u003e \u0026,不便于浏览,使用本方法不会转义

func RemoveBbCode

func RemoveBbCode(value interface{}) string

去除discuz中简单的BBCode代码

func RemoveHTML

func RemoveHTML(value interface{}) string

过滤所有html标签,包括注释

func Required

func Required(value interface{}) bool

检测值不为空,和IsEmpty返回值相反

func SpecialCharsDecode

func SpecialCharsDecode(value interface{}) string

将specialEntities里面的实体字符转换成specialChars里对应的字符

func SpecialCharsEncode

func SpecialCharsEncode(value interface{}) string

将specialChars转换成对应的specialEntities里对应的实体

func Str2Bytes

func Str2Bytes(s string) []byte

Str2Bytes 零拷贝

func StripSlashes

func StripSlashes(value interface{}) string

将转义过的字符去除反斜杠

func StructCopy

func StructCopy(DstStructPtr interface{}, SrcStructPtr interface{}) error

StructCopy 结构体复制 Example:

src := &Src{"katy", "000"}
var dst Dst
StructCopy(&dst, src)

func StructValidator

func StructValidator(args ...interface{}) error

进行结构体验证

func ToDateTime

func ToDateTime(args ...string) (time.Time, error)

ToDateTime 将指定格式的时间字符串转换为时间对象 第一个参数为代表时间的字符串 第二个参数为时间格式,默认是 2006-01-02 15:04:05

Types

This section is empty.

Jump to

Keyboard shortcuts

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