golibs

package module
v2020.605.1840+incompa... Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: MIT Imports: 38 Imported by: 33

README

#golibs

go通用库

Documentation

Index

Constants

View Source
const (
	Time_TIMEyyyyMMdd           string = "20060102"
	Time_TIMEStandard           string = "2006-01-02 15:04:05"
	Time_TIME_HH_mm_ss          string = "15:04:05"
	Time_TIMEMSSQL              string = "2006-01-02T15:04:05.999Z"
	Time_TIMEMYSQL              string = "2006-01-02T15:04:05+08:00"
	Time_TIMEyyyyMMddHHmmss     string = "20060102150405"
	Time_TIMEyyyyMMddHHmmssffff string = "200601021504059999"
	Time_TIMEJavaUtilDate       string = "20060102150405000-0700"
	Time_TIMEISO8601            string = "2006-01-02T15:04:05.999-0700"
)
View Source
const VERSION = "2020.605.1840"

Variables

View Source
var (
	// Epoch is set to the twitter snowflake epoch of Nov 04 2010 01:42:54 UTC
	// You may customize this to set a different epoch for your application.
	Epoch int64 = 1288834974657

	// Number of bits to use for Node
	// Remember, you have a total 22 bits to share between Node/Step
	NodeBits uint8 = 10

	// Number of bits to use for Step
	// Remember, you have a total 22 bits to share between Node/Step
	StepBits uint8 = 12
)
View Source
var (
	GetFileSuffixRegex         = regexp.MustCompile(".(jpg|jpeg|png|gif|exe|doc|docx|ppt|pptx|xls|xlsx)")
	IsTaobaoNickRegex          = regexp.MustCompile(`(^[\\u4e00-\\u9fa5\\w_—\\-,。…·〔〕()!@¥%……&*?、;‘“]*$)`)
	IsSubTaobaoNickRegex       = regexp.MustCompile(`(^[\\u4e00-\\u9fa5\\w_—\\-,。…·〔〕()!@¥%……&*?、;‘“:]*$)`)
	IsVersionRegex             = regexp.MustCompile(`(^[0-9.]*$)`)
	IsUrlRegex                 = regexp.MustCompile(`(^[a-zA-z]+://[^\s]*$)`)
	IsNumberRegex              = regexp.MustCompile(`(^[0-9]*$)`)
	IsAsciiRegex               = regexp.MustCompile(`(^[\x00-\xff]*$)`)
	IsMultipNumberRegex        = regexp.MustCompile(`(^[0-9,]*$)`)
	IsLetterOrNumberRegex      = regexp.MustCompile(`(^[A-Za-z0-9_]*$)`)
	IsLetterOrNumber1Regex     = regexp.MustCompile(`(^[A-Za-z0-9_-]*$)`)
	IsHanOrLetterOrNumberRegex = regexp.MustCompile("^[A-Za-z0-9_\u4e00-\u9fa5-]*$")
	IsGeneralStringRegex       = regexp.MustCompile("^[A-Za-z0-9_\\-#+./:\u4e00-\u9fa5]*$")
	IsStandardTimeRegex        = regexp.MustCompile(`^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$`)
	IsIPAddressRegecx          = regexp.MustCompile(`^((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}$`)
	IsIntranetIPRegex          = regexp.MustCompile(`^(127\.0\.0\.1)|(10\.\d{1,3}\.\d{1,3}\.\d{1,3})|(172\.((1[6-9])|(2\d)|(3[01]))\.\d{1,3}\.\d{1,3})|(192\.168\.\d{1,3}\.\d{1,3})$`)
	IsEmailRegex               = regexp.MustCompile(`^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$`)
	IsMobileRegex              = regexp.MustCompile("^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][2,5,6,7])|([7][0-8])|([8][0-9])|([9][1,3,5,8,9]))[0-9]{8}$")
)
View Source
var ErrInvalidBase32 = errors.New("invalid base32")

ErrInvalidBase32 is returned by ParseBase32 when given an invalid []byte

View Source
var ErrInvalidBase58 = errors.New("invalid base58")

ErrInvalidBase58 is returned by ParseBase58 when given an invalid []byte

Functions

func AesDecrypt

func AesDecrypt(crypted, key, iv []byte) ([]byte, error)

func AesEncrypt

func AesEncrypt(plaintext, key, iv []byte) ([]byte, error)

func ApiSign

func ApiSign(params url.Values, secret string) string

api签名,用于开放平台

func ApiSignIsValid

func ApiSignIsValid(params url.Values, secret string) bool

api签名,用于开放平台

func Base64

func Base64(src []byte) string

func BcryptEncrypt

func BcryptEncrypt(message []byte) ([]byte, error)

func BuildRequestUrl

func BuildRequestUrl(requestUrl string, params url.Values) string

获取url和参数列表对应的完整请求url

func ByteToGByte

func ByteToGByte(byte_value float64) string

func BytesToUInt

func BytesToUInt(b []byte) uint32

字节转换成整形

func CacheCount

func CacheCount() int

func CacheDel

func CacheDel(key string)

func CacheGetBool

func CacheGetBool(key string) (value bool, ok bool)

func CacheGetByteArray

func CacheGetByteArray(key string) (value []byte, ok bool)

func CacheGetInt

func CacheGetInt(key string) (value int, ok bool)

func CacheGetInt64

func CacheGetInt64(key string) (value int64, ok bool)

func CacheGetString

func CacheGetString(key string) (value string, ok bool)

func CacheGetTime

func CacheGetTime(key string) (value time.Time, ok bool)

func CacheSet

func CacheSet(key string, value interface{})

func CheckBcrypt

func CheckBcrypt(hashBytes, s []byte) (bool, error)

func ConfusedTwo

func ConfusedTwo(sourceBytes []byte) []byte

混淆[]byte

func DesDecrypt

func DesDecrypt(crypted, key, iv []byte) ([]byte, error)

func DesEncrypt

func DesEncrypt(origData, key, iv []byte) ([]byte, error)

func FormatJson

func FormatJson(data interface{}) string

格式化为Json字符串

func From2000Nano

func From2000Nano() int64

返回从2000-01-01 00:00:00到现在经过的纳秒数

func GenerateSign

func GenerateSign(params map[string]string, secret string, taobao_nick string, time int64) string

func GenerateSignNoUser

func GenerateSignNoUser(params map[string]string, secret string) string

func Get

func Get(requestUrl string) (int, string, error)

获取url对应的内容,返回信息:StatusCode,body,err

func GetByAuthToken

func GetByAuthToken(requestUrl, authToken string) (int, string, error)

带上AuthToken,发起一个get请求

func GetByToken

func GetByToken(requestUrl, token string) (int, string, error)

带上Bearer Token,发起一个get请求

func GetCRC32

func GetCRC32(s string) uint32

func GetCurrentDirectory

func GetCurrentDirectory() string

获取程序运行路径

func GetCurrentIntranetIP

func GetCurrentIntranetIP() string

获取当前内网IP

func GetDate

func GetDate(t time.Time) int

获取当前日期

func GetFileSuffix

func GetFileSuffix(s string) string

获取文件扩展名

func GetGuid

func GetGuid() string

获取一个Guid

func GetIPAddressNotPort

func GetIPAddressNotPort(ip_address string) string

获取IP地址,不包含端口号

func GetIPNums

func GetIPNums(s string) (ipNum uint32, err error)

把IP地址转成数字

func GetPwd

func GetPwd(lenth int) string

生成随机密码,短时间内会重复

func GetSimplePwd

func GetSimplePwd(lenth int) string

生成简单随机密码,短时间内会重复

func GetTimeInt64

func GetTimeInt64() int64

获取当前时间的int64格式,yyyyMMddHHmmss

func HTMLEncode

func HTMLEncode(s string) string

html编码

func HexStringToBytes

func HexStringToBytes(hex_str string) []byte

把十六进制字符串转成字节数组

func HmacMd5

func HmacMd5(message, secret []byte) []byte

func HmacSha1

func HmacSha1(message, secret []byte) []byte

func HmacSha256

func HmacSha256(message, secret []byte) []byte

func HmacSha512

func HmacSha512(message, secret []byte) []byte

func IsAllChineseChar

func IsAllChineseChar(s string) bool

判断字符串是否全中文字符

func IsAscii

func IsAscii(s string) bool

是否Ascii字符

func IsEmail

func IsEmail(s string) bool

是否email

func IsGeneralString

func IsGeneralString(s string) bool

判断是否由汉字、字母、数字、下划线、中杠等组成

func IsHanOrLetterOrNumber

func IsHanOrLetterOrNumber(s string) bool

判断是否由汉字、字母、数字、下划线组成

func IsIPAddress

func IsIPAddress(s string) bool

是否IPv4地址

func IsIntranetIP

func IsIntranetIP(s string) bool

是否内网IP地址

func IsLetterOrNumber

func IsLetterOrNumber(s string) bool

判断是否由字母、数字、下划线组成

func IsLetterOrNumber1

func IsLetterOrNumber1(s string) bool

判断是否由字母、数字、下划线组成

func IsMobile

func IsMobile(s string) bool

是否手机号

func IsMultipNumber

func IsMultipNumber(s string) bool

是否多数字(用逗号间隔)

func IsNumber

func IsNumber(s string) bool

是否数字

func IsStandardTime

func IsStandardTime(s string) bool

判断是否标准时间格式

func IsSubTaobaoNick

func IsSubTaobaoNick(s string) bool

判断是否是淘宝用户名(子帐号)

func IsTaobaoNick

func IsTaobaoNick(s string) bool

判断是否是淘宝用户名

func IsUrl

func IsUrl(s string) bool

判断是否网址

func IsUtf8

func IsUtf8(s string) bool

是否utf-8编码字符串

func IsVersion

func IsVersion(s string) bool

判断是否版本号

func Length

func Length(str string) int

使用 utf8.RuneCountInString()统计字符串长度

func Md5

func Md5(s string) string

func Method

func Method(r *http.Request) string

获取当前连接的Http方法

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

func PKCS7Unpadding

func PKCS7Unpadding(origData []byte) []byte

func ParseRequestQuery

func ParseRequestQuery(req string) (params url.Values, err error)

解析请求参数到一个url.Values对象

func Post

func Post(requestUrl string, params url.Values) (int, string, error)

获取url对应的内容,返回信息:StatusCode,body,err

func PostBody

func PostBody(requestUrl string, reqBody string) (int, string, error)

用Post方法获取url对应的内容,提交body,返回信息:StatusCode,body,err

func PostByAuthToken

func PostByAuthToken(requestUrl string, authToken string, params url.Values) (int, string, error)

获取url对应的内容,返回信息:StatusCode,body,err

func PostByToken

func PostByToken(requestUrl, token string) (int, string, error)

带上Bearer Token,发起一个post请求,无内容

func PostFile

func PostFile(requestUrl string, params url.Values, field_name, path string) (int, string, error)

获取url对应的内容,同时上传文件,返回信息:StatusCode,body,err

func PostJson

func PostJson(requestUrl string, params map[string]string) (int, string, error)

用Post方法获取url对应的内容,提交json,返回信息:StatusCode,body,err

func PostJsonByToken

func PostJsonByToken(requestUrl, token, jsonString string) (int, string, error)

带上Bearer Token,发起一个post请求,内容是json

func RandInt64

func RandInt64(min, max int64) int64

生成指定范围内的int64数字

func ReversalBytes

func ReversalBytes(source []byte) []byte

反转[]byte

func ReverseString

func ReverseString(s string) string

字符串逆序

func Sha1

func Sha1(message []byte) []byte

func Since

func Since(t time.Time) int64

Since返回从t到现在经过的毫秒数

func Sleep

func Sleep(t time.Time, delay int64)

延时delay毫秒,从t开始计时

func SliceByteToString

func SliceByteToString(b []byte) string

string()

func StandardTime

func StandardTime() string

返回当前时间字符串

func Strim

func Strim(s string) string

删除空格、换行、空格等字符

func String2Unicode

func String2Unicode(s string) string

字符串转成Unicode编码

func StringToSliceByte

func StringToSliceByte(s string) []byte

[]byte()

func SubString

func SubString(s string, pos, length int) string

字串截取

func TimeStringToTime

func TimeStringToTime(sourceTime string) (time.Time, error)

把时间字符串转成本地时间

func ToConfusedBase64

func ToConfusedBase64(str string) string

混淆-->base64

func ToConfusedZipBase64

func ToConfusedZipBase64(str string) string

混淆-->zlib压缩-->base64

func ToJson

func ToJson(data interface{}) string

序列化为json

func ToJsonConfusedBase64

func ToJsonConfusedBase64(obj interface{}) string

序列化-->混淆-->base64

func ToJsonZipConfusedBase64

func ToJsonZipConfusedBase64(obj interface{}) string

序列化-->zlib压缩-->混淆-->base64

func TopSign

func TopSign(params url.Values, secret string) string

func UIntToBytes

func UIntToBytes(value uint32) []byte

整形转换成字节

func UnBase64

func UnBase64(source string) ([]byte, error)

func UnConfusedTwo

func UnConfusedTwo(confusedBytes []byte) []byte

反混淆[]byte

func UnZipMd5

func UnZipMd5(zip_string string) (md5_string string, err error)

解压缩汉字,结果为guid或md5值

func Unicode2String

func Unicode2String(s string) (to string, err error)

Unicode编码转成字符串

func Unix

func Unix() int64

返回当前时间戳(秒)

func UnixMilliSecond

func UnixMilliSecond() int64

返回当前时间戳(毫秒)

func UnixNano

func UnixNano() int64

返回当前时间戳(纳秒)

func UrlDecode

func UrlDecode(source string) (string, error)

func UrlEncode

func UrlEncode(source string) string

func Version2Time

func Version2Time(version string) (t time.Time, err error)

版本号转时间,格式:2019.905.1052

func ZipMd5

func ZipMd5(md5String string) (zip_string string, err error)

压缩md5或guid

func ZlibUnzipBytes

func ZlibUnzipBytes(input []byte) ([]byte, error)

func ZlibZipBytes

func ZlibZipBytes(input []byte) ([]byte, error)

Types

type ID

type ID int64

An ID is a custom type used for a snowflake ID. This is used so we can attach methods onto the ID.

func ParseBase32

func ParseBase32(b []byte) (ID, error)

ParseBase32 parses a base32 []byte into a snowflake ID NOTE: There are many different base32 implementations so becareful when doing any interoperation interop with other packages.

func ParseBase58

func ParseBase58(b []byte) (ID, error)

ParseBase58 parses a base58 []byte into a snowflake ID

func (ID) Base2

func (f ID) Base2() string

Base2 returns a string base2 of the snowflake ID

func (ID) Base32

func (f ID) Base32() string

Base32 uses the z-base-32 character set but encodes and decodes similar to base58, allowing it to create an even smaller result string. NOTE: There are many different base32 implementations so becareful when doing any interoperation interop with other packages.

func (ID) Base36

func (f ID) Base36() string

Base36 returns a base36 string of the snowflake ID

func (ID) Base58

func (f ID) Base58() string

Base58 returns a base58 string of the snowflake ID

func (ID) Base64

func (f ID) Base64() string

Base64 returns a base64 string of the snowflake ID

func (ID) Bytes

func (f ID) Bytes() []byte

Bytes returns a byte slice of the snowflake ID

func (ID) Int64

func (f ID) Int64() int64

Int64 returns an int64 of the snowflake ID

func (ID) IntBytes

func (f ID) IntBytes() [8]byte

IntBytes returns an array of bytes of the snowflake ID, encoded as a big endian integer.

func (ID) MarshalJSON

func (f ID) MarshalJSON() ([]byte, error)

MarshalJSON returns a json byte array string of the snowflake ID.

func (ID) Node

func (f ID) Node() int64

Node returns an int64 of the snowflake ID node number

func (ID) Step

func (f ID) Step() int64

Step returns an int64 of the snowflake step (or sequence) number

func (ID) String

func (f ID) String() string

String returns a string of the snowflake ID

func (ID) Time

func (f ID) Time() int64

Time returns an int64 unix timestamp of the snowflake ID time

func (*ID) UnmarshalJSON

func (f *ID) UnmarshalJSON(b []byte) error

UnmarshalJSON converts a json byte array of a snowflake ID into an ID type.

type JSONSyntaxError

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

A JSONSyntaxError is returned from UnmarshalJSON if an invalid ID is provided.

func (JSONSyntaxError) Error

func (j JSONSyntaxError) Error() string

type Node

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

A Node struct holds the basic information needed for a snowflake generator node

func NewNode

func NewNode(node int64) (*Node, error)

NewNode returns a new snowflake node that can be used to generate snowflake IDs

func (*Node) Generate

func (n *Node) Generate() ID

Generate creates and returns a unique snowflake ID

func (*Node) GetTime

func (n *Node) GetTime(i int64) time.Time

type StringBuilder

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

func NewStringBuilder

func NewStringBuilder() *StringBuilder

func (*StringBuilder) Append

func (this *StringBuilder) Append(obj interface{}) *StringBuilder

func (*StringBuilder) ToString

func (this *StringBuilder) ToString() string

Directories

Path Synopsis
gbtree
B+ Tree
B+ Tree
gchan
优雅的Channel操作.
优雅的Channel操作.
glist
并发安全的双向链表.
并发安全的双向链表.
gmap
并发安全的哈希MAP.
并发安全的哈希MAP.
gqueue
并发安全的动态队列.
并发安全的动态队列.
gset
并发安全的集合SET.
并发安全的集合SET.
Goroutine池.
Goroutine池.
时间管理
时间管理
gconv
类型转换.
类型转换.
gidgen
ID生成器.
ID生成器.
grand
随机数管理
随机数管理
gregx
正则表达式
正则表达式
gutil
其他工具包
其他工具包

Jump to

Keyboard shortcuts

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