common

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: GPL-3.0 Imports: 12 Imported by: 57

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BigIntToDecimals

func BigIntToDecimals(amount *big.Int, decimals int32) decimal.Decimal

func BoolToUInt

func BoolToUInt(b bool) uint64

func Bytes2Hex

func Bytes2Hex(d []byte) string

Bytes2Hex returns the hexadecimal encoding of d.

func Contain

func Contain(obj interface{}, target interface{}) bool

Contain 判断obj是否在target中,target支持的类型arrary,slice,map

func CopyBytes

func CopyBytes(b []byte) (copiedBytes []byte)

CopyBytes returns an exact copy of the provided bytes.

func FormatStruct

func FormatStruct(v interface{}) string

func FromHex

func FromHex(s string) []byte

FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func Hex2BytesFixed

func Hex2BytesFixed(str string, flen int) []byte

Hex2BytesFixed returns bytes of a specified fixed length flen.

func IntToDecimals

func IntToDecimals(amount int64, decimals int32) decimal.Decimal

func IsChinaMobile

func IsChinaMobile(b []byte) bool

检验是否为合法的中国手机号, 不是那么太精细 只要是 13,14,15,18 开头的 11 位数字就认为是中国手机号

func IsChinaMobileString

func IsChinaMobileString(str string) bool

同 func IsChinaMobile(b []byte) bool

func IsMail

func IsMail(b []byte) bool

检验是否为合法的电子邮箱, 考虑到各个网站的 mail 要求不一样, 这里匹配比较宽松 邮箱用户名可以包含 0-9, A-Z, a-z, -, _, . 开头字母不能是 -, _, . 结尾字母不能是 -, _, . -, _, . 这三个连接字母任意两个不能连续, 如不能出现 --, __, .., -_, -., _. 邮箱的域名可以包含 0-9, A-Z, a-z, - 连接字符 - 只能出现在中间, 不能连续, 如不能 -- 支持多级域名, x@y.z, x@y.z.w, x@x.y.z.w.e

func IsMailString

func IsMailString(str string) bool

同 func IsMail(b []byte) bool

func IsNickname

func IsNickname(b []byte) bool

检验是否为合法的昵称, 合法的字符有 0-9, A-Z, a-z, _, 汉字 字符 '_' 只能出现在中间且不能重复, 如 "__"

func IsNicknameString

func IsNicknameString(str string) bool

同 func IsNickname(b []byte) bool

func IsNumber

func IsNumber(b []byte) bool

IsNumber 是否整数值

func IsNumberString

func IsNumberString(str string) bool

同 func IsNumber(b []byte) bool

func IsRealNumber

func IsRealNumber(b []byte) bool

IsRealNumber 是否实数值

func IsRealNumberString

func IsRealNumberString(str string) bool

同 func IsRealNumber(b []byte) bool

func IsUserName

func IsUserName(b []byte) bool

检验是否为合法的用户名, 合法的字符有 0-9, A-Z, a-z, _ 第一个字母不能为 _, 0-9 最后一个字母不能为 _, 且 _ 不能连续

func IsUserNameString

func IsUserNameString(str string) bool

同 func IsName(b []byte) bool

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

LeftPadBytes zero-pads slice to the left up to length l.

func RightPadBytes

func RightPadBytes(slice []byte, l int) []byte

RightPadBytes zero-pads slice to the right up to length l.

func StringNumToBigIntWithExp

func StringNumToBigIntWithExp(amount string, exp int32) *big.Int

func StringValueToBigInt

func StringValueToBigInt(value string, base int) (*big.Int, error)

func Substr

func Substr(str string, start int, end int) string

func TimeFormat

func TimeFormat(format string, t ...time.Time) string

timeFormat 格式化时间 @param format 在go中,为2006-01-02 15:04:05

func ToHex deprecated

func ToHex(b []byte) string

ToHex returns the hex representation of b, prefixed with '0x'. For empty slices, the return value is "0x0".

Deprecated: use hexutil.Encode instead.

func ToHexArray

func ToHexArray(b [][]byte) []string

ToHexArray creates a array of hex-string based on []byte

func ToISO8601

func ToISO8601(t ...time.Time) string

func UIntToBool

func UIntToBool(u uint64) bool

Types

type FloatProtocal

type FloatProtocal interface {
	Float32(def ...float32) float32
	Float64(def ...float64) float64
}

FloatProtocal 强化float的扩展方法

type Int

type Int int

Int 强化int类型

func (Int) String

func (v Int) String() string

ToString int转为string类型

type IntProtocal

type IntProtocal interface {
	Int(def ...int) int
	Int8(def ...int8) int8
	Int16(def ...int16) int16
	Int32(def ...int32) int32
	Int64(def ...int64) int64
}

IntProtocal 强化int的扩展方法

type String

type String string

String AT的字符串库

const (
	// NilString 定义空串的关键字
	NilString String = "<nil>"
)

func NewString

func NewString(value interface{}, def ...String) String

NewString 初始化字符串,自动转型

func NewStringByBool

func NewStringByBool(v bool) String

NewStringByBool 通过bool初始化字符串

func NewStringByFloat

func NewStringByFloat(v float64) String

NewStringByFloat 通过float初始化字符串

func NewStringByInt

func NewStringByInt(v int64) String

NewStringByInt 通过int初始化字符串

func NewStringByUInt

func NewStringByUInt(v uint64) String

NewStringByUInt 通过int初始化字符串

func (String) AES

func (s String) AES(key string) (string, error)

AES AES加密 key 密钥key hex字符串 return 密文

func (String) Bool

func (s String) Bool(def ...bool) bool

Bool string转布尔型

func (String) Float32

func (s String) Float32(def ...float32) float32

Float32 String转为float32

func (String) Float64

func (s String) Float64(def ...float64) float64

Float64 String转为float64

func (String) HmacMD5

func (s String) HmacMD5(secret string) string

HmacMD5 字符串转为HmacMD5后的hash md5

func (String) HmacSHA1

func (s String) HmacSHA1(secret string) string

HmacSHA1 字符串转为HmacSHA1后的hash hex

func (String) Int

func (s String) Int(def ...int) int

Int String类型转为int类型

func (String) Int16

func (s String) Int16(def ...int) int16

Int16 String类型转为int32类型

func (String) Int32

func (s String) Int32(def ...int) int32

Int32 String类型转为int32类型

func (String) Int64

func (s String) Int64(def ...int) int64

Int64 String类型转为int64类型

func (String) Int8

func (s String) Int8(def ...int) int8

Int8 String类型转为int8类型

func (String) IsEmpty

func (s String) IsEmpty() bool

IsEmpty 是否空值

func (String) IsNil

func (s String) IsNil() bool

IsNil 判断是否空指针

func (String) Length

func (s String) Length() int

Length 字符串长度,支持中文字等等的计算

func (String) MD5

func (s String) MD5() string

MD5 字符串转为MD5后的hash hex

func (String) SHA1

func (s String) SHA1() string

SHA1 字符串转为SHA1后的hash hex

func (String) SHA256

func (s String) SHA256() string

SHA256 字符串转为SHA256后的hash hex

func (String) String

func (s String) String() string

String 转string

func (String) UInt16

func (s String) UInt16(def ...int) uint16

UInt16 String类型转为uint32类型

func (String) UInt32

func (s String) UInt32(def ...int) uint32

UInt32 String类型转为uint32类型

func (String) UInt64

func (s String) UInt64(def ...int) uint64

UInt64 String类型转为uint64类型

func (String) UInt8

func (s String) UInt8(def ...int) uint8

UInt8 String类型转为uint8类型

func (*String) UnAES

func (s *String) UnAES(aesBase64string string, key string) error

UnAES 通过base64编码的aes密文初始化一个字符串 aesBase64string base64编码的aes密文 key 密钥字符串 return 明文

type StringProtocal

type StringProtocal interface {
	String() string
	Length() int
	IsNil() bool
	IsEmpty() bool
}

StringProtocal 强化String的扩展方法

Directories

Path Synopsis
Package file provides simple utility functions to be used with files
Package file provides simple utility functions to be used with files

Jump to

Keyboard shortcuts

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