Documentation ¶
Index ¶
- Constants
- Variables
- func AesDecrypt(crypted, key, iv []byte) ([]byte, error)
- func AesEncrypt(plaintext, key, iv []byte) ([]byte, error)
- func ApiSign(params url.Values, secret string) string
- func ApiSignIsValid(params url.Values, secret string) bool
- func Base64(src []byte) string
- func BcryptEncrypt(message []byte) ([]byte, error)
- func BuildRequestUrl(requestUrl string, params url.Values) string
- func ByteToGByte(byte_value float64) string
- func BytesToUInt(b []byte) uint32
- func CacheCount() int
- func CacheDel(key string)
- func CacheGetBool(key string) (value bool, ok bool)
- func CacheGetByteArray(key string) (value []byte, ok bool)
- func CacheGetInt(key string) (value int, ok bool)
- func CacheGetInt64(key string) (value int64, ok bool)
- func CacheGetString(key string) (value string, ok bool)
- func CacheGetTime(key string) (value time.Time, ok bool)
- func CacheSet(key string, value interface{})
- func CheckBcrypt(hashBytes, s []byte) (bool, error)
- func ConfusedTwo(sourceBytes []byte) []byte
- func CreateMultiDir(filePath string) error
- func DesDecrypt(crypted, key, iv []byte) ([]byte, error)
- func DesEncrypt(origData, key, iv []byte) ([]byte, error)
- func FormatJson(data interface{}) string
- func From2000Nano() int64
- func GenUUID32() string
- func GenUUID36() string
- func GenUniqueId() string
- func GenerateSign(params map[string]string, secret string, taobao_nick string, time int64) string
- func GenerateSignNoUser(params map[string]string, secret string) string
- func Get(requestUrl string) (int, string, error)
- func GetByAuthToken(requestUrl, authToken string) (int, string, error)
- func GetByToken(requestUrl, token string) (int, string, error)
- func GetCRC32(s string) uint32
- func GetCurrentDirectory() string
- func GetCurrentIntranetIP() string
- func GetDate(t time.Time) int
- func GetFileSuffix(s string) string
- func GetGuid() string
- func GetIPAddressNotPort(ip_address string) string
- func GetIPNums(s string) (ipNum uint32, err error)
- func GetPwd(lenth int) string
- func GetSimplePwd(lenth int) string
- func GetTimeInt64() int64
- func HTMLEncode(s string) string
- func HexStringToBytes(hex_str string) []byte
- func HmacMd5(message, secret []byte) []byte
- func HmacSha1(message, secret []byte) []byte
- func HmacSha256(message, secret []byte) []byte
- func HmacSha512(message, secret []byte) []byte
- func HomePath() (string, error)
- func IsAllChineseChar(s string) bool
- func IsAscii(s string) bool
- func IsEmail(s string) bool
- func IsGeneralString(s string) bool
- func IsHanOrLetterOrNumber(s string) bool
- func IsIPAddress(s string) bool
- func IsIntranetIP(s string) bool
- func IsLetterOrNumber(s string) bool
- func IsLetterOrNumber1(s string) bool
- func IsMobile(s string) bool
- func IsMultipNumber(s string) bool
- func IsNumber(s string) bool
- func IsStandardTime(s string) bool
- func IsSubTaobaoNick(s string) bool
- func IsTaobaoNick(s string) bool
- func IsUrl(s string) bool
- func IsUtf8(s string) bool
- func IsVersion(s string) bool
- func Length(str string) int
- func Md5(s string) string
- func Method(r *http.Request) string
- func PKCS7Padding(ciphertext []byte, blockSize int) []byte
- func PKCS7Unpadding(origData []byte) []byte
- func ParseRequestQuery(req string) (params url.Values, err error)
- func Post(requestUrl string, params url.Values) (int, string, error)
- func PostBody(requestUrl string, reqBody string) (int, string, error)
- func PostByAuthToken(requestUrl string, authToken string, params url.Values) (int, string, error)
- func PostByToken(requestUrl, token string) (int, string, error)
- func PostFile(requestUrl string, params url.Values, field_name, path string) (int, string, error)
- func PostJson(requestUrl string, params map[string]string) (int, string, error)
- func PostJsonByToken(requestUrl, token, jsonString string) (int, string, error)
- func RandInt64(min, max int64) int64
- func RemoveDuplicateStrings(strs []string) []string
- func ReversalBytes(source []byte) []byte
- func ReverseString(s string) string
- func Sha1(message []byte) []byte
- func Sha256(bs []byte) []byte
- func Sha512(bs []byte) []byte
- func Since(t time.Time) int64
- func Sleep(t time.Time, delay int64)
- func SliceByteToString(b []byte) string
- func StandardTime() string
- func Strim(s string) string
- func String2Unicode(s string) string
- func StringToSliceByte(s string) []byte
- func SubString(s string, pos, length int) string
- func TimeStringToTime(sourceTime string) (time.Time, error)
- func ToConfusedBase64(str string) string
- func ToConfusedZipBase64(str string) string
- func ToJson(data interface{}) string
- func ToJsonConfusedBase64(obj interface{}) string
- func ToJsonZipConfusedBase64(obj interface{}) string
- func TopSign(params url.Values, secret string) string
- func UIntToBytes(value uint32) []byte
- func UnBase64(source string) ([]byte, error)
- func UnConfusedTwo(confusedBytes []byte) []byte
- func UnZipMd5(zip_string string) (md5_string string, err error)
- func Unicode2String(s string) (to string, err error)
- func Unix() int64
- func UnixMilliSecond() int64
- func UnixNano() int64
- func UrlDecode(source string) (string, error)
- func UrlEncode(source string) string
- func Version2Time(version string) (t time.Time, err error)
- func ZipMd5(md5String string) (zip_string string, err error)
- func ZlibUnzipBytes(input []byte) ([]byte, error)
- func ZlibZipBytes(input []byte) ([]byte, error)
- type Cache
- func (cache *Cache) AverageAccessTime() int64
- func (cache *Cache) Clear()
- func (cache *Cache) Del(key []byte) (affected bool)
- func (cache *Cache) DelInt(key int64) (affected bool)
- func (cache *Cache) EntryCount() (entryCount int64)
- func (cache *Cache) EvacuateCount() (count int64)
- func (cache *Cache) ExpiredCount() (count int64)
- func (cache *Cache) Get(key []byte) (value []byte, err error)
- func (cache *Cache) GetInt(key int64) (value []byte, err error)
- func (cache *Cache) GetIntWithExpiration(key int64) (value []byte, expireAt uint32, err error)
- func (cache *Cache) GetOrSet(key, value []byte, expireSeconds int) (retValue []byte, err error)
- func (cache *Cache) GetWithBuf(key, buf []byte) (value []byte, err error)
- func (cache *Cache) GetWithExpiration(key []byte) (value []byte, expireAt uint32, err error)
- func (cache *Cache) HitCount() (count int64)
- func (cache *Cache) HitRate() float64
- func (cache *Cache) Incr(key []byte, expireSeconds int) (value int64, err error)
- func (cache *Cache) LookupCount() int64
- func (cache *Cache) MissCount() (count int64)
- func (cache *Cache) NewIterator() *Iterator
- func (cache *Cache) OverwriteCount() (overwriteCount int64)
- func (cache *Cache) Peek(key []byte) (value []byte, err error)
- func (cache *Cache) ResetStatistics()
- func (cache *Cache) Set(key, value []byte, expireSeconds int) (err error)
- func (cache *Cache) SetInt(key int64, value []byte, expireSeconds int) (err error)
- func (cache *Cache) TTL(key []byte) (timeLeft uint32, err error)
- func (cache *Cache) Touch(key []byte, expireSeconds int) (err error)
- func (cache *Cache) TouchedCount() (touchedCount int64)
- type Entry
- type ID
- func (f ID) Base2() string
- func (f ID) Base32() string
- func (f ID) Base36() string
- func (f ID) Base58() string
- func (f ID) Base64() string
- func (f ID) Bytes() []byte
- func (f ID) Int64() int64
- func (f ID) IntBytes() [8]byte
- func (f ID) MarshalJSON() ([]byte, error)
- func (f ID) Node() int64
- func (f ID) Step() int64
- func (f ID) String() string
- func (f ID) Time() int64
- func (f *ID) UnmarshalJSON(b []byte) error
- type Iterator
- type JSONSyntaxError
- type LimitWaitGroup
- type Node
- type RingBuf
- func (rb *RingBuf) Begin() int64
- func (rb *RingBuf) Dump() []byte
- func (rb *RingBuf) End() int64
- func (rb *RingBuf) EqualAt(p []byte, off int64) bool
- func (rb *RingBuf) Evacuate(off int64, length int) (newOff int64)
- func (rb *RingBuf) ReadAt(p []byte, off int64) (n int, err error)
- func (rb *RingBuf) Resize(newSize int)
- func (rb *RingBuf) Size() int64
- func (rb *RingBuf) Skip(length int64)
- func (rb *RingBuf) String() string
- func (rb *RingBuf) Write(p []byte) (n int, err error)
- func (rb *RingBuf) WriteAt(p []byte, off int64) (n int, err error)
- type StringBuilder
- type Timer
Constants ¶
const ( Time_TIMEyyyyMMdd string = "20060102" Time_TIMEyyyy_MM_dd string = "2006-01-02" 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.000Z" 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.000-0700" )
const ENTRY_HDR_SIZE = 24
const HASH_ENTRY_SIZE = 16
const VERSION = "v1.2024.116"
Variables ¶
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 )
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(`^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$`) IsMobileRegex = regexp.MustCompile(`^1[3456789]\d{9}$`) )
var ErrInvalidBase32 = errors.New("invalid base32")
ErrInvalidBase32 is returned by ParseBase32 when given an invalid []byte
var ErrInvalidBase58 = errors.New("invalid base58")
ErrInvalidBase58 is returned by ParseBase58 when given an invalid []byte
var ErrLargeEntry = errors.New("The entry size is larger than 1/1024 of cache size")
var ErrLargeKey = errors.New("The key is larger than 65535")
var ErrNotFound = errors.New("Entry not found")
var ErrOutOfRange = errors.New("out of range")
Functions ¶
func AesDecrypt ¶
func AesEncrypt ¶
func BcryptEncrypt ¶
func BuildRequestUrl ¶
获取url和参数列表对应的完整请求url
func ByteToGByte ¶
func CacheCount ¶
func CacheCount() int
func CacheGetBool ¶
func CacheGetByteArray ¶
func CacheGetInt ¶
func CacheGetInt64 ¶
func CacheGetString ¶
func CheckBcrypt ¶
func CreateMultiDir ¶
CreateMultiDir 调用os.MkdirAll递归创建文件夹
func DesDecrypt ¶
func DesEncrypt ¶
func GenerateSign ¶
func GetByAuthToken ¶
带上AuthToken,发起一个get请求
func GetByToken ¶
带上Bearer Token,发起一个get请求
func HmacSha256 ¶
func HmacSha512 ¶
func PKCS7Padding ¶
func PKCS7Unpadding ¶
func ParseRequestQuery ¶
解析请求参数到一个url.Values对象
func PostByAuthToken ¶
获取url对应的内容,返回信息:StatusCode,body,err
func PostByToken ¶
带上Bearer Token,发起一个post请求,无内容
func PostJsonByToken ¶
带上Bearer Token,发起一个post请求,内容是json
func RemoveDuplicateStrings ¶
RemoveDuplicateStrings 字符串切片去重
func ToJsonZipConfusedBase64 ¶
func ToJsonZipConfusedBase64(obj interface{}) string
序列化-->zlib压缩-->混淆-->base64
func Version2Time ¶
版本号转时间,格式:2019.905.1052
func ZlibUnzipBytes ¶
func ZlibZipBytes ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a freecache instance.
func NewCache ¶
NewCache returns a newly initialize cache by size. The cache size will be set to 512KB at minimum. If the size is set relatively large, you should call `debug.SetGCPercent()`, set it to a much smaller value to limit the memory consumption and GC pause time.
func NewCacheCustomTimer ¶
NewCacheCustomTimer returns new cache with custom timer.
func (*Cache) AverageAccessTime ¶
AverageAccessTime returns the average unix timestamp when a entry being accessed. Entries have greater access time will be evacuated when it is about to be overwritten by new value.
func (*Cache) Del ¶
Del deletes an item in the cache by key and returns true or false if a delete occurred.
func (*Cache) DelInt ¶
DelInt deletes an item in the cache by int key and returns true or false if a delete occurred.
func (*Cache) EntryCount ¶
EntryCount returns the number of items currently in the cache.
func (*Cache) EvacuateCount ¶
EvacuateCount is a metric indicating the number of times an eviction occurred.
func (*Cache) ExpiredCount ¶
ExpiredCount is a metric indicating the number of times an expire occurred.
func (*Cache) GetInt ¶
GetInt returns the value for an integer within the cache or a not found error.
func (*Cache) GetIntWithExpiration ¶
GetIntWithExpiration returns the value and expiration or a not found error.
func (*Cache) GetOrSet ¶
GetOrSet returns existing value or if record doesn't exist it sets a new key, value and expiration for a cache entry and stores it in the cache, returns nil in that case
func (*Cache) GetWithBuf ¶
GetWithBuf copies the value to the buf or returns not found error. This method doesn't allocate memory when the capacity of buf is greater or equal to value.
func (*Cache) GetWithExpiration ¶
GetWithExpiration returns the value with expiration or not found error.
func (*Cache) HitCount ¶
HitCount is a metric that returns number of times a key was found in the cache.
func (*Cache) LookupCount ¶
LookupCount is a metric that returns the number of times a lookup for a given key occurred.
func (*Cache) MissCount ¶
MissCount is a metric that returns the number of times a miss occurred in the cache.
func (*Cache) NewIterator ¶
NewIterator creates a new iterator for the cache.
func (*Cache) OverwriteCount ¶
OverwriteCount indicates the number of times entries have been overriden.
func (*Cache) Peek ¶
Peek returns the value or not found error, without updating access time or counters.
func (*Cache) ResetStatistics ¶
func (cache *Cache) ResetStatistics()
ResetStatistics refreshes the current state of the statistics.
func (*Cache) Set ¶
Set sets a key, value and expiration for a cache entry and stores it in the cache. If the key is larger than 65535 or value is larger than 1/1024 of the cache size, the entry will not be written to the cache. expireSeconds <= 0 means no expire, but it can be evicted when cache is full.
func (*Cache) Touch ¶
Touch updates the expiration time of an existing key. expireSeconds <= 0 means no expire, but it can be evicted when cache is full.
func (*Cache) TouchedCount ¶
TouchedCount indicates the number of times entries have had their expiration time extended.
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 ¶
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 ¶
ParseBase58 parses a base58 []byte into a snowflake ID
func (ID) Base32 ¶
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) IntBytes ¶
IntBytes returns an array of bytes of the snowflake ID, encoded as a big endian integer.
func (ID) MarshalJSON ¶
MarshalJSON returns a json byte array string of the snowflake ID.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON converts a json byte array of a snowflake ID into an ID type.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator iterates the entries for the cache.
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 LimitWaitGroup ¶
type LimitWaitGroup struct {
// contains filtered or unexported fields
}
func NewLimitWaitGroup ¶
func NewLimitWaitGroup(limit int) *LimitWaitGroup
func (*LimitWaitGroup) Add ¶
func (s *LimitWaitGroup) Add() error
func (*LimitWaitGroup) AddWithContext ¶
func (s *LimitWaitGroup) AddWithContext(ctx context.Context) error
func (*LimitWaitGroup) Done ¶
func (s *LimitWaitGroup) Done()
func (*LimitWaitGroup) Wait ¶
func (s *LimitWaitGroup) Wait()
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
A Node struct holds the basic information needed for a snowflake generator node
type RingBuf ¶
type RingBuf struct {
// contains filtered or unexported fields
}
Ring buffer has a fixed size, when data exceeds the size, old data will be overwritten by new data. It only contains the data in the stream from begin to end
func NewRingBuf ¶
func (*RingBuf) Evacuate ¶
Evacuate read the data at off, then write it to the the data stream, Keep it from being overwritten by new data.
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
Source Files ¶
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
其他工具包
|
其他工具包 |