zlib

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: MulanPSL-2.0 Imports: 74 Imported by: 0

Documentation

Overview

Package zlib provides ...

Package zlib provides ...

Package zlib provides ...

Package zlib provides ...

Index

Constants

View Source
const (
	// DefaultRetryTimes times of retry
	DefaultRetryTimes = 5
	// DefaultRetryDuration time duration of two retries
	DefaultRetryDuration = time.Second * 3
)
View Source
const (
	// Version 版本号
	Version = "1.0.0"

	// KDelimiter 本库自定义分隔符
	KDelimiter = "$@#KSYSK#@$"

	Unknown = "Unknown"

	//UINT_MAX 无符号整型uint最大值
	UINT_MAX = ^uint(0)

	//UINT8_MAX 无符号整型uint8最大值, 255
	UINT8_MAX = ^uint8(0)

	//UINT16_MAX 无符号整型uint16最大值, 65535
	UINT16_MAX = ^uint16(0)

	//UINT32_MAX 无符号整型uint32最大值, 4294967295
	UINT32_MAX = ^uint32(0)

	//UINT64_MAX 无符号整型uint64最大值, 18446744073709551615
	UINT64_MAX = ^uint64(0)

	//INT_MAX 有符号整型int最大值
	INT_MAX = int(^uint(0) >> 1)
	//INT_MIN 有符号整型int最小值
	INT_MIN = ^INT_MAX

	//INT32_MAX 有符号整型int32最大值, 2147483647
	INT32_MAX = int32(^uint32(0) >> 1)
	//INT32_MIN 有符号整型int32最小值, -2147483648
	INT32_MIN = ^INT32_MAX

	//INT64_MAX 有符号整型int64最大值, 9223372036854775807
	INT64_MAX = int64(^uint64(0) >> 1)
	//INT64_MIN 有符号整型int64最小值, -9223372036854775808
	INT64_MIN = ^INT64_MAX

	// FILE_COVER_ALLOW 文件覆盖,允许
	FILE_COVER_ALLOW LkkFileCover = 1
	// FILE_COVER_IGNORE 文件覆盖,忽略
	FILE_COVER_IGNORE LkkFileCover = 0
	// FILE_COVER_DENY 文件覆盖,禁止
	FILE_COVER_DENY LkkFileCover = -1

	// FILE_TYPE_ANY 文件类型-任意
	FILE_TYPE_ANY LkkFileType = 0
	// FILE_TYPE_LINK 文件类型-链接文件
	FILE_TYPE_LINK LkkFileType = 1
	// FILE_TYPE_REGULAR 文件类型-常规文件(不包括链接)
	FILE_TYPE_REGULAR LkkFileType = 2
	// FILE_TYPE_COMMON 文件类型-普通文件(包括常规和链接)
	FILE_TYPE_COMMON LkkFileType = 3

	// FILE_TREE_ALL 文件树,查找所有(包括目录和文件)
	FILE_TREE_ALL LkkFileTree = 3
	// FILE_TREE_DIR 文件树,仅查找目录
	FILE_TREE_DIR LkkFileTree = 2
	// FILE_TREE_FILE 文件树,仅查找文件
	FILE_TREE_FILE LkkFileTree = 1

	// RAND_STRING_ALPHA 随机字符串类型,字母
	RAND_STRING_ALPHA LkkRandString = 0
	// RAND_STRING_NUMERIC 随机字符串类型,数值
	RAND_STRING_NUMERIC LkkRandString = 1
	// RAND_STRING_ALPHANUM 随机字符串类型,字母+数值
	RAND_STRING_ALPHANUM LkkRandString = 2
	// RAND_STRING_SPECIAL 随机字符串类型,字母+数值+特殊字符
	RAND_STRING_SPECIAL LkkRandString = 3
	// RAND_STRING_CHINESE 随机字符串类型,仅中文
	RAND_STRING_CHINESE LkkRandString = 4

	// CASE_NONE 忽略大小写
	CASE_NONE LkkCaseSwitch = 0
	// CASE_LOWER 检查小写
	CASE_LOWER LkkCaseSwitch = 1
	// CASE_UPPER 检查大写
	CASE_UPPER LkkCaseSwitch = 2

	// PAD_LEFT 左侧填充
	PAD_LEFT LkkPadType = 0
	// PAD_RIGHT 右侧填充
	PAD_RIGHT LkkPadType = 1
	// PAD_BOTH 两侧填充
	PAD_BOTH LkkPadType = 2

	// PKCS_NONE 不进行填充
	PKCS_NONE LkkPKCSType = -1
	// PKCS_ZERO PKCS 0值填充
	PKCS_ZERO LkkPKCSType = 0
	// PKCS_SEVEN 即PKCS7
	PKCS_SEVEN LkkPKCSType = 7

	// COMPARE_ONLY_VALUE 仅比较值
	COMPARE_ONLY_VALUE LkkArrCompareType = 0
	// COMPARE_ONLY_KEY 仅比较键
	COMPARE_ONLY_KEY LkkArrCompareType = 1
	// COMPARE_BOTH_KEYVALUE 同时比较键和值
	COMPARE_BOTH_KEYVALUE LkkArrCompareType = 2

	//默认浮点数精确小数位数
	FLOAT_DECIMAL uint8 = 8

	//AuthCode 动态密钥长度,须<32
	DYNAMIC_KEY_LEN = 8

	//检查连接超时的时间
	CHECK_CONNECT_TIMEOUT = time.Second * 5

	// 正则模式-全中文
	PATTERN_CHINESE_ALL = "^[\u4e00-\u9fa5]+$"

	// 正则模式-中文名称
	PATTERN_CHINESE_NAME = "^[\u4e00-\u9fa5][.•·\u4e00-\u9fa5]{0,30}[\u4e00-\u9fa5]$"

	// 正则模式-多字节字符
	PATTERN_MULTIBYTE = "[^\x00-\x7F]"

	// 正则模式-ASCII字符
	PATTERN_ASCII = "^[\x00-\x7F]+$"

	// 正则模式-全角字符
	PATTERN_FULLWIDTH = "[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]"

	// 正则模式-半角字符
	PATTERN_HALFWIDTH = "[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]"

	// 正则模式-词语,不以下划线开头的中文、英文、数字、下划线
	PATTERN_WORD = "^[a-zA-Z0-9\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]+$"

	// 正则模式-浮点数
	PATTERN_FLOAT = `^(-?\d+)(\.\d+)`

	// 正则模式-邮箱
	PATTERN_EMAIL = "" /* 133-byte string literal not displayed */

	// 正则模式-用户名-英文
	PATTERN_USERNAMEEN = `^[a-zA-Z0-9_.]+$`

	// 正则模式-大陆手机号
	PATTERN_MOBILECN = `^1[3-9]\d{9}$`

	// 正则模式-固定电话
	PATTERN_TEL_FIX = `^(010|02\d{1}|0[3-9]\d{2})-\d{7,9}(-\d+)?$`

	// 正则模式-400或800
	PATTERN_TEL_4800 = `^[48]00\d?(-?\d{3,4}){2}$`

	// 正则模式-座机号(固定电话或400或800)
	PATTERN_TELEPHONE = `(` + PATTERN_TEL_FIX + `)|(` + PATTERN_TEL_4800 + `)`

	// 正则模式-电话(手机或固话)
	PATTERN_PHONE = `(` + PATTERN_MOBILECN + `)|(` + PATTERN_TEL_FIX + `)`

	// 正则模式-日期时间
	PATTERN_DATETIME = `^[0-9]{4}(|\-[0-9]{2}(|\-[0-9]{2}(|\s+[0-9]{2}(|:[0-9]{2}(|:[0-9]{2})))))$`

	// 正则模式-身份证号码,18位或15位
	PATTERN_CREDIT_NO = `` /* 158-byte string literal not displayed */

	// 正则模式-小写英文
	PATTERN_ALPHA_LOWER = `^[a-z]+$`

	// 正则模式-大写英文
	PATTERN_ALPHA_UPPER = `^[A-Z]+$`

	// 正则模式-字母或数字
	PATTERN_ALPHA_NUMERIC = `^[a-zA-Z0-9]+$`

	// 正则模式-十六进制颜色
	PATTERN_HEXCOLOR = `^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$`

	// 正则模式-RGB颜色
	PATTERN_RGBCOLOR = "" /* 157-byte string literal not displayed */

	// 正则模式-全空白字符
	PATTERN_WHITESPACE_ALL = "^[[:space:]]+$"

	// 正则模式-带空白字符
	PATTERN_WHITESPACE_HAS = ".*[[:space:]]"

	// 正则模式-连续空白符
	PATTERN_WHITESPACE_DUPLICATE = `[[:space:]]{2,}|[\s\p{Zs}]{2,}`

	// 正则模式-base64字符串
	PATTERN_BASE64 = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$"

	// 正则模式-base64编码图片
	PATTERN_BASE64_IMAGE = `^data:\s*(image|img)\/(\w+);base64`

	// 正则模式-html标签
	PATTERN_HTML_TAGS = `<(.|\n)*?>`

	// 正则模式-DNS名称
	PATTERN_DNSNAME = `^([a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*[\._]?$`

	// 正则模式-MD5
	PATTERN_MD5 = `^(?i)([0-9a-h]{32})$`

	// 正则模式-SHA1
	PATTERN_SHA1 = `^(?i)([0-9a-h]{40})$`

	// 正则模式-SHA256
	PATTERN_SHA256 = `^(?i)([0-9a-h]{64})$`

	// 正则模式-SHA512
	PATTERN_SHA512 = `^(?i)([0-9a-h]{128})$`

	//正则模式-等式 x = y
	PATTERN_EQUATION = `['"]?([\w\-]+)['"]?[\s]*=[\s]*['"]?(.*)['"]?`

	// 正则模式-emoji表情符
	PATTERN_EMOJI = `` /* 21966-byte string literal not displayed */
)
View Source
const (
	OneMinSec  = 60
	OneHourSec = 3600
	OneDaySec  = 86400
	OneWeekSec = 7 * 86400

	OneMin  = time.Minute
	OneHour = time.Hour
	OneDay  = 24 * time.Hour
	OneWeek = 7 * 24 * time.Hour
)
View Source
const (
	Separator = string(filepath.Separator)
)

Variables

View Source
var (
	// 已编译的正则
	RegFormatDir             = regexp.MustCompile(`[\/]{2,}`) //连续的"//"或"\\"或"\/"或"/\"
	RegChineseAll            = regexp.MustCompile(PATTERN_CHINESE_ALL)
	RegChineseName           = regexp.MustCompile(PATTERN_CHINESE_NAME)
	RegWord                  = regexp.MustCompile(PATTERN_WORD)
	RegMultiByte             = regexp.MustCompile(PATTERN_MULTIBYTE)
	RegFullWidth             = regexp.MustCompile(PATTERN_FULLWIDTH)
	RegHalfWidth             = regexp.MustCompile(PATTERN_HALFWIDTH)
	RegFloat                 = regexp.MustCompile(PATTERN_FLOAT)
	RegEmail                 = regexp.MustCompile(PATTERN_EMAIL)
	RegMobilecn              = regexp.MustCompile(PATTERN_MOBILECN)
	RegTelephone             = regexp.MustCompile(PATTERN_TELEPHONE)
	RegPhone                 = regexp.MustCompile(PATTERN_PHONE)
	RegDatetime              = regexp.MustCompile(PATTERN_DATETIME)
	RegCreditno              = regexp.MustCompile(PATTERN_CREDIT_NO)
	RegAlphaLower            = regexp.MustCompile(PATTERN_ALPHA_LOWER)
	RegAlphaUpper            = regexp.MustCompile(PATTERN_ALPHA_UPPER)
	RegAlphaNumeric          = regexp.MustCompile(PATTERN_ALPHA_NUMERIC)
	RegHexcolor              = regexp.MustCompile(PATTERN_HEXCOLOR)
	RegRgbcolor              = regexp.MustCompile(PATTERN_RGBCOLOR)
	RegWhitespace            = regexp.MustCompile(`\s`)
	RegWhitespaceAll         = regexp.MustCompile(PATTERN_WHITESPACE_ALL)
	RegWhitespaceHas         = regexp.MustCompile(PATTERN_WHITESPACE_HAS)
	RegWhitespaceDuplicate   = regexp.MustCompile(PATTERN_WHITESPACE_DUPLICATE)
	RegBase64                = regexp.MustCompile(PATTERN_BASE64)
	RegBase64Image           = regexp.MustCompile(PATTERN_BASE64_IMAGE)
	RegHtmlTag               = regexp.MustCompile(PATTERN_HTML_TAGS)
	RegDNSname               = regexp.MustCompile(PATTERN_DNSNAME)
	RegUrlBackslashDuplicate = regexp.MustCompile(`([^:])[\/]{2,}`) //url中连续的"//"或"\\"或"\/"或"/\"
	RegMd5                   = regexp.MustCompile(PATTERN_MD5)
	RegSha1                  = regexp.MustCompile(PATTERN_SHA1)
	RegSha256                = regexp.MustCompile(PATTERN_SHA256)
	RegSha512                = regexp.MustCompile(PATTERN_SHA512)
	RegEmoji                 = regexp.MustCompile(PATTERN_EMOJI)
	RegUsernameen            = regexp.MustCompile(PATTERN_USERNAMEEN)
	RegEquation              = regexp.MustCompile(PATTERN_EQUATION)
	RegAscii                 = regexp.MustCompile(PATTERN_ASCII)
)

公开变量

View Source
var (
	// DefaultLayout template for format time
	DefaultTimeLayout = "2006-01-02 15:04:05"
)
View Source
var (
	ImageExtList = []string{"bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx", "svg", "psd", "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "wmf", "webp", "avif", "apng"}
)

私有变量

Functions

func AbsFloat

func AbsFloat(number float64) float64

AbsFloat 浮点型取绝对值.

func AbsInt

func AbsInt(number int64) int64

AbsInt 整型取绝对值.

func AbsInt16

func AbsInt16(n int16) int16

AbsInt16 gets absolute value of int16.

func AbsInt32

func AbsInt32(n int32) int32

AbsInt32 gets absolute value of int32.

func AbsInt64

func AbsInt64(n int64) int64

AbsInt64 gets absolute value of int64.

func AbsInt8

func AbsInt8(n int8) int8

(n ^ shifted) - shifted = 5 - 0 = 5

func AbsPath

func AbsPath(fpath string) string

AbsPath 获取绝对路径,path可允许不存在.

func AddDay

func AddDay(t time.Time, day int) time.Time

AddDay add some day time for given time

func AddHour

func AddHour(t time.Time, hour int) time.Time

AddHour add some hour time for given time

func AddMinutes

func AddMinutes(t time.Time, minutes int) time.Time

AddMinutes add some minutes time for given time

func AddMonth

func AddMonth(t time.Time, month int) time.Time

AddMonth add some month time for given time

func AddNanoseconds

func AddNanoseconds(t time.Time, nanoSeconds int) time.Time

AddNanoseconds add some seconds time for given time

func AddSeconds

func AddSeconds(t time.Time, seconds int) time.Time

AddSeconds add some seconds time for given time

func AddYear

func AddYear(t time.Time, year int) time.Time

AddYear add some year time for given time

func Addslashes

func Addslashes(str string) string

Addslashes 使用反斜线引用字符串.

func AesDecrypt

func AesDecrypt(decryptStr string, key []byte, iv string) (string, error)

解密

func AesEncrypt

func AesEncrypt(encryptStr string, key []byte, iv string) (string, error)

加密 aes_128_cbc

func After

func After(n int, fn interface{}) func(args ...interface{}) []reflect.Value

After creates a function that invokes func once it's called n or more times

func AppendFile

func AppendFile(fpath string, data []byte) error

AppendFile 插入文件内容.

func Array2String

func Array2String(array []interface{}) string

将数组格式化为字符串

func ArrayChunk

func ArrayChunk(arr interface{}, size int) [][]interface{}

ArrayChunk 将一个数组/切片分割成多个,size为每个子数组的长度.

func ArrayColumn

func ArrayColumn(arr interface{}, columnKey string) []interface{}

ArrayColumn 返回数组(切片/字典/结构体)中元素指定的一列. arr的元素必须是字典; columnKey为元素的字段名; 该方法效率较低.

func ArrayDiff

func ArrayDiff(arr1, arr2 interface{}, compareType LkkArrCompareType) map[interface{}]interface{}

ArrayDiff 计算数组(数组/切片/字典)的交集,返回在 arr1 中但不在 arr2 里的元素,注意会同时返回键. compareType为两个数组的比较方式,枚举类型,有: COMPARE_ONLY_VALUE 根据元素值比较, 返回在 arr1 中但是不在arr2 里的值; COMPARE_ONLY_KEY 根据 arr1 中的键名和 arr2 进行比较,返回不同键名的项; COMPARE_BOTH_KEYVALUE 同时比较键和值.

func ArrayFlip

func ArrayFlip(arr interface{}) map[interface{}]interface{}

ArrayFlip 交换数组(切片/字典)中的键和值.

func ArrayInterfaceToString

func ArrayInterfaceToString(_array interface{}) string

ArrayInterfaceToString interface转string,准对一维数组[]string{}或[]int{}

func ArrayIntersect

func ArrayIntersect(arr1, arr2 interface{}, compareType LkkArrCompareType) map[interface{}]interface{}

ArrayIntersect 计算数组(数组/切片/字典)的交集,返回在 arr1 中且在 arr2 里的元素,注意会同时返回键. compareType为两个数组的比较方式,枚举类型,有: COMPARE_ONLY_VALUE 根据元素值比较, 返回在 arr1 中且在arr2 里的值; COMPARE_ONLY_KEY 根据 arr1 中的键名和 arr2 进行比较,返回相同键名的项; COMPARE_BOTH_KEYVALUE 同时比较键和值.

func ArrayKeyExists

func ArrayKeyExists(key interface{}, arr interface{}) bool

ArrayKeyExists 检查arr(数组/切片/字典/结构体)里是否有key指定的键名(索引/字段).

func ArrayKeys

func ArrayKeys(arr interface{}) []interface{}

ArrayKeys 返回数组(切片/字典/结构体)中所有的键名;如果是结构体,只返回公开的字段.

func ArrayPad

func ArrayPad(arr interface{}, size int, item interface{}) []interface{}

ArrayPad 以指定长度将一个值item填充进arr数组/切片. 若 size 为正,则填补到数组的右侧,如果为负则从左侧开始填补; 若 size 的绝对值小于或等于 arr 数组的长度则没有任何填补.

func ArrayRand

func ArrayRand(arr interface{}, num int) []interface{}

ArrayRand 从数组(切片/字典)中随机取出num个元素.

func ArrayReverse

func ArrayReverse(arr interface{}) []interface{}

ArrayReverse 返回单元顺序相反的数组(仅限数组和切片).

func ArrayReverseString

func ArrayReverseString(ss []string)

Reverse string slice [site user info 0] -> [0 info user site]

func ArraySearchItem

func ArraySearchItem(arr interface{}, condition map[string]interface{}) (res interface{})

ArraySearchItem 从数组(切片/字典)中搜索对应元素(单个). arr为要查找的数组,元素必须为字典/结构体;condition为条件字典.

func ArraySearchMutil

func ArraySearchMutil(arr interface{}, condition map[string]interface{}) (res []interface{})

ArraySearchMutil 从数组(切片/字典)中搜索对应元素(多个). arr为要查找的数组,元素必须为字典/结构体;condition为条件字典.

func ArrayShuffle

func ArrayShuffle(arr interface{}) []interface{}

ArrayShuffle 打乱数组/切片排序.

func ArrayStringsRemove

func ArrayStringsRemove(ss []string, s string) []string

StringsRemove a value form a string slice

func ArrayUnique

func ArrayUnique(arr interface{}) map[interface{}]interface{}

ArrayUnique 移除数组(切片/字典)中重复的值,返回字典,保留键名.

func ArrayValues

func ArrayValues(arr interface{}, filterZero bool) []interface{}

arrayValues 返回arr(数组/切片/字典/结构体)中所有的值. filterZero 是否过滤零值元素(nil,false,0,”,[]),true时排除零值元素,false时保留零值元素.

func AtWho

func AtWho(text string, minLen ...int) []string

AtWho 查找被@的用户名.minLen为用户名最小长度,默认5.

func Average

func Average(nums ...interface{}) (res float64)

Average 对任意类型序列中的数值类型求平均值,忽略非数值的.

func AverageFloat64

func AverageFloat64(nums ...float64) (res float64)

AverageFloat64 对浮点数序列求平均值.

func AverageInt

func AverageInt(nums ...int) (res float64)

AverageInt 对整数序列求平均值.

func Basename

func Basename(path string) string

func Before

func Before(n int, fn interface{}) func(args ...interface{}) []reflect.Value

Before creates a function that invokes func once it's called less than n times

func Big5ToUtf8

func Big5ToUtf8(s []byte) ([]byte, error)

Big5ToUtf8 BIG5转UTF-8编码.

func BinToDec

func BinToDec(str string) (int64, error)

Bin2Dec 将二进制字符串转换为十进制.

func BinToHex

func BinToHex(str string) (string, error)

BinToHex 将二进制字符串转换为十六进制字符串.

func BoolToInt

func BoolToInt(val bool) int

func Br2nl

func Br2nl(str string) string

Br2nl 将br标签转换为换行符.

func BuildQueryMap

func BuildQueryMap(result map[string]interface{}, keys []string, value interface{}) error

buildQueryMap 创建URL Query参数字典. result 为结果字典;keys 为键数组;value为键值.

func ByteFormat

func ByteFormat(size float64, decimal uint8, delimiter string) string

ByteFormat 格式化文件比特大小. size为文件大小,decimal为要保留的小数位数,delimiter为数字和单位间的分隔符.

func ByteToString

func ByteToString(_byte []byte) string

func ByteToStringFast

func ByteToStringFast(_byte []byte) string

func CallFunc

func CallFunc(f interface{}, args ...interface{}) (results []interface{}, err error)

CallFunc 动态调用函数.

func CallMethod

func CallMethod(t interface{}, method string, args ...interface{}) ([]interface{}, error)

CallMethod 调用对象的方法. 若执行成功,则结果是该方法的返回结果; 否则返回(nil, error).

func CamelCaseToLowerCase

func CamelCaseToLowerCase(str string, connector rune) string

CamelCaseToLowerCase 驼峰转为小写.

func Ceil

func Ceil(value float64) float64

Ceil 向上取整.

func Chdir

func Chdir(dir string) error

Chdir 改变/进入新的工作目录.

func Chmod

func Chmod(filename string, mode os.FileMode) bool

Chmod 改变文件模式.

func ChmodBatch

func ChmodBatch(fpath string, filemode, dirmode os.FileMode) (res bool)

ChmodBatch 批量改变路径权限模式(包括子目录和所属文件). filemode为文件权限模式,dirmode为目录权限模式.

func Chown

func Chown(filename string, uid, gid int) bool

Chown 改变文件的所有者.

func Chr

func Chr(chr uint) string

Chr 返回相对应于 ASCII 所指定的单个字符.

func ChunkBytes

func ChunkBytes(bs []byte, size int) [][]byte

ChunkBytes 将字节切片分割为多个小块.其中size为每块的长度.

func ChunkSplit

func ChunkSplit(str string, chunklen uint, end string) string

ChunkSplit 将字符串分割成小块.str为要分割的字符,chunklen为分割的尺寸,end为行尾序列符号.

func ClearUrlPrefix

func ClearUrlPrefix(str string, prefix ...string) string

ClearUrlPrefix 清除URL的前缀; str为URL字符串,prefix为前缀,默认"/".

func ClearUrlSuffix

func ClearUrlSuffix(str string, suffix ...string) string

ClearUrlSuffix 清除URL的后缀; str为URL字符串,suffix为后缀,默认"/".

func ClientIp

func ClientIp(req *http.Request) string

ClientIp 获取客户端真实IP,req为http请求.

func ClosestWord

func ClosestWord(word string, searchs []string) (string, int)

ClosestWord 获取与原字符串相似度最高的字符串,以及它们的编辑距离. word为原字符串,searchs为待查找的字符串数组.

func CompareEQ

func CompareEQ(lhs, rhs interface{}) bool

func CompareGE

func CompareGE(lhs, rhs interface{}) bool

func CompareGT

func CompareGT(lhs, rhs interface{}) bool

func CompareLE

func CompareLE(lhs, rhs interface{}) bool

func CompareLT

func CompareLT(lhs, rhs interface{}) bool

func Compose

func Compose(fnList ...func(...interface{}) interface{}) func(...interface{}) interface{}

Compose compose the functions from right to left

func CopyDir

func CopyDir(source string, dest string, cover LkkFileCover) (int64, error)

CopyDir 拷贝源目录到目标目录,cover为枚举(FILE_COVER_ALLOW、FILE_COVER_IGNORE、FILE_COVER_DENY).

func CopyFile

func CopyFile(source string, dest string, cover LkkFileCover) (int64, error)

CopyFile 拷贝源文件到目标文件,cover为枚举(FILE_COVER_ALLOW、FILE_COVER_IGNORE、FILE_COVER_DENY).

func CopyLink(source string, dest string) error

CopyLink 拷贝链接.

func CopyStruct

func CopyStruct(dest interface{}, resources ...interface{}) interface{}

CopyStruct 将resources的值拷贝到dest目标结构体; 要求dest必须是结构体指针,resources为多个源结构体;若resources存在多个相同字段的元素,结果以最后的为准; 只简单核对字段名,无错误处理,需开发自行检查dest和resources字段类型才可操作.

func CountBase64Byte

func CountBase64Byte(str string) (res int)

CountBase64Byte 粗略统计base64字符串大小,字节.

func CountLines

func CountLines(fpath string, buffLength int) (int, error)

CountLines 统计文件行数.buffLength为缓冲长度,kb.

func CountWords

func CountWords(str string) (int, map[string]int)

CountWords 统计字符串中单词的使用情况. 返回结果:单词总数;和一个字典,包含每个单词的单独统计. 因为没有分词,对中文尚未很好支持.

func CpuUsage

func CpuUsage() (user, idle, total uint64)

CpuUsage 获取CPU使用率(darwin系统必须使用cgo),单位jiffies(节拍数). user为用户态(用户进程)的运行时间, idle为空闲时间, total为累计时间.

func Crc32

func Crc32(str string) uint32

Crc32 计算一个字符串的 crc32 多项式.

func CtxGo added in v1.0.2

func CtxGo(ctx context.Context, f func())

CtxGo is preferred than Go.

func CutSlice

func CutSlice(arr interface{}, offset, size int) []interface{}

CutSlice 裁剪切片,返回根据offset(起始位置)和size(数量)参数所指定的arr(数组/切片)中的一段切片.

func DBC2SBC

func DBC2SBC(s string) string

DBC2SBC 半角转全角.

func DateToTimeS

func DateToTimeS(_date string, format string) int64

DateToTimeS 秒日期时间戳转时间戳,s

func DayEnd

func DayEnd(t time.Time) time.Time

DayEnd time for given time

func DayStart

func DayStart(t time.Time) time.Time

DayStart time for given time

func Debounced

func Debounced(fn func(), duration time.Duration) func()

Debounced creates a debounced function that delays invoking fn until after wait duration have elapsed since the last time the debounced function was invoked.

func DecToBin

func DecToBin(num int64) string

Dec2Bin 将十进制转换为二进制字符串.

func DecToHex

func DecToHex(num int64) string

DecToHex 将十进制转换为十六进制.

func DecToOct

func DecToOct(num int64) string

Dec2Oct 将十进制转换为八进制.

func DecodeBase64

func DecodeBase64(_string string) string

DecodeBase64 解密base64(标准方式)

func DecodeByte

func DecodeByte(data []byte, target interface{}) error

DecodeByte decode byte data to target object

func DecodeURL

func DecodeURL(_url string) (string, error)

DecodeURL 解义url

func DecodeUrlBase64

func DecodeUrlBase64(_string string) string

DecodeUrlBase64 解密文件和url名安全型base64

func DelDir

func DelDir(dir string, delete bool) error

DelDir 删除目录.delete为true时连该目录一起删除;为false时只清空该目录.

func Delay

func Delay(delay time.Duration, fn interface{}, args ...interface{})

Delay make the function execution after delayed time

func DeleteInt16Slice

func DeleteInt16Slice(src []int16, indexes ...int) []int16

DeleteInt16Slice deletes int16 slice elements by indexes.

func DeleteInt32Slice

func DeleteInt32Slice(src []int32, indexes ...int) []int32

DeleteInt32Slice deletes int32 slice elements by indexes.

func DeleteInt64Slice

func DeleteInt64Slice(src []int64, indexes ...int) []int64

DeleteInt64Slice deletes int64 slice elements by indexes.

func DeleteInt8Slice

func DeleteInt8Slice(src []int8, indexes ...int) []int8

DeleteInt8Slice deletes int8 slice elements by indexes.

func DeleteIntSlice

func DeleteIntSlice(src []int, indexes ...int) []int

DeleteIntSlice deletes int slice elements by indexes.

func DeleteSlice

func DeleteSlice(slice interface{}, indexes ...int) interface{}

DeleteSlice deletes the specified index element from the slice. Note that the original slice will not be modified.

func DeleteSliceE

func DeleteSliceE(slice interface{}, indexes ...int) (interface{}, error)

DeleteSliceE deletes the specified index element from the slice with error. Note that the original slice will not be modified.

func DeleteSliceElms

func DeleteSliceElms(i interface{}, elms ...interface{}) interface{}

DeleteSliceElms deletes the specified elements from the slice. Note that the original slice will not be modified.

func DeleteSliceElmsE

func DeleteSliceElmsE(i interface{}, elms ...interface{}) (interface{}, error)

DeleteSliceElmsE deletes the specified elements from the slice. Note that the original slice will not be modified.

func DeleteSliceItems

func DeleteSliceItems(val interface{}, ids ...int) (res []interface{}, del int)

DeleteSliceItems 删除数组/切片的元素,返回一个新切片. ids为多个元素的索引(0~len(val)-1); del为删除元素的数量.

func DeleteStrSlice

func DeleteStrSlice(src []string, indexes ...int) []string

DeleteStrSlice deletes string slice elements by indexes.

func DeleteUint16Slice

func DeleteUint16Slice(src []int, indexes ...int) []uint16

DeleteUint16Slice deletes uint16 slice elements by indexes.

func DeleteUint32Slice

func DeleteUint32Slice(src []uint32, indexes ...int) []uint32

DeleteUint32Slice deletes uint32 slice elements by indexes.

func DeleteUint64Slice

func DeleteUint64Slice(src []uint64, indexes ...int) []uint64

DeleteUint64Slice deletes uint64 slice elements by indexes.

func DeleteUint8Slice

func DeleteUint8Slice(src []int8, indexes ...int) []uint8

DeleteUint8Slice deletes uint8 slice elements by indexes.

func DeleteUintSlice

func DeleteUintSlice(src []int, indexes ...int) []uint

DeleteUintSlice deletes uint slice elements by indexes.

func DetectEncoding

func DetectEncoding(str string) (res string)

DetectEncoding 匹配字符编码,TODO.

func Dir

func Dir(path string) string

func DirSize

func DirSize(fpath string) int64

DirSize 获取目录大小(bytes字节).

func Dirname

func Dirname(fpath string) string

Dirname 返回路径中的目录部分,注意空路径或无目录的返回".".

func DiskUsage

func DiskUsage(path string) (used, free, total uint64)

DiskUsage 获取磁盘(目录)使用情况,单位字节.参数path为路径. used为已用, free为空闲, total为总数.

func Dstrpos

func Dstrpos(str string, arr []string, chkCase bool) (bool, string)

Dstrpos 检查字符串str是否包含数组arr的元素之一,返回检查结果和匹配的字符串. chkCase为是否检查大小写.

func DumpPrint

func DumpPrint(vs ...interface{})

dumpPrint 打印调试变量,变量可多个.

func Empty

func Empty(val interface{}) bool

判断变量是否为空

func EncodeBase64

func EncodeBase64(_string string) string

EncodeBase64 生成base64(标准方式)

func EncodeByte

func EncodeByte(data interface{}) ([]byte, error)

EncodeByte encode data to byte

func EncodeURL

func EncodeURL(_url string) string

EncodeURL 转义url或转义其他字符

func EncodeUrlBase64

func EncodeUrlBase64(_string string) string

EncodeUrlBase64 加密文件和url名安全型base64

func EndsWith

func EndsWith(str, sub string, ignoreCase bool) bool

EndsWith 字符串str是否以sub结尾.

func EndsWiths

func EndsWiths(str string, subs []string, ignoreCase bool) (res bool)

EndsWiths 字符串str是否以subs其中之一为结尾.

func Exec

func Exec(command string) (retInt int, outStr, errStr []byte)

Exec 执行一个外部命令. retInt为1时失败,为0时成功;outStr为执行命令的输出;errStr为错误输出. 命令如 "ls -a" "/bin/bash -c \"ls -a\""

func Exp

func Exp(x float64) float64

Exp 计算 e 的指数.

func Explode

func Explode(str string, delimiters ...string) (res []string)

Explode 字符串分割.delimiters为分隔符,可选,支持多个.

func Expm1

func Expm1(x float64) float64

Expm1 返回 exp(x) - 1.

func Ext

func Ext(path string) string

func ExtName

func ExtName(path string) string

func FileGetBytes

func FileGetBytes(filenameOrURL string, timeout ...time.Duration) ([]byte, error)

func FileGetCSV

func FileGetCSV(filenameOrURL string, timeout ...time.Duration) ([][]string, error)

func FileGetContent

func FileGetContent(path string) (string, error)

func FilePutContent

func FilePutContent(path string, content string, isAppend bool) error

func FileSetBytes

func FileSetBytes(filename string, data []byte) error

func FileSetCSV

func FileSetCSV(filename string, records [][]string) error

func FileSize

func FileSize(fpath string) int64

FileSize 获取文件大小(bytes字节);注意:文件不存在或无法访问时返回-1 .

func FileTree

func FileTree(fpath string, ftype LkkFileTree, recursive bool, filters ...FileFilter) []string

FileTree 获取目录的文件树列表. ftype为枚举(FILE_TREE_ALL、FILE_TREE_DIR、FILE_TREE_FILE); recursive为是否递归; filters为一个或多个文件过滤器函数,FileFilter类型.

func FilterHTML

func FilterHTML(html string) string

func FilterIframe

func FilterIframe(html string) string

FilterIframe 过滤iframe

func FilterJS

func FilterJS(html string) string

FilterJS 过滤html中的js

func FilterStyle

func FilterStyle(html string) string

FilterStyle 过滤html中的style

func FilterToLower

func FilterToLower(html string) string

func FilterXML

func FilterXML(html string) string

FilterXML 过滤xml

func FirstLetter

func FirstLetter(str string) string

FirstLetter 获取字符串首字母.

func FloatEqual

func FloatEqual(f1 float64, f2 float64, decimal ...uint8) (res bool)

FloatEqual 比较两个浮点数是否相等.decimal为小数精确位数,默认为 FLOAT_DECIMAL . 有效数值是长度(包括小数点)为17位之内的数值,最后一位会四舍五入.

func FloatToString

func FloatToString(val interface{}, decimal int) string

FloatToString 将浮点数转换为字符串,decimal为小数位数.

func Floor

func Floor(value float64) float64

Floor 向下取整.

func ForceGC

func ForceGC()

ForceGC 强制手动GC垃圾回收(阻塞).

func Format

func Format(t time.Time) string

Format use default layout

func FormatBy

func FormatBy(t time.Time, layout string) string

FormatBy given default layout

func FormatDir

func FormatDir(fpath string) string

formatDir 格式化目录,将"\","//"替换为"/",且以"/"结尾.

func FormatPath

func FormatPath(fpath string) string

formatPath 格式化路径.

func FormatUnix

func FormatUnix(sec int64) string

FormatUnix time seconds use default layout

func FormatUnixBy

func FormatUnixBy(sec int64, layout string) string

FormatUnixBy format time seconds use given layout

func FormatUrl

func FormatUrl(str string) string

FormatUrl 格式化URL.

func GbkToUtf8

func GbkToUtf8(s []byte) ([]byte, error)

GbkToUtf8 GBK转UTF-8编码.

func GenUUID

func GenUUID() string

func GeoDistance

func GeoDistance(lng1, lat1, lng2, lat2 float64) float64

GeoDistance 获取地理距离/米. 参数分别为两点的经度和纬度:lat:-90~90,lng:-180~180.

func Get

func Get(url string) string

发送GET请求 url: 请求地址 response: 请求返回的内容

func GetCallDir

func GetCallDir() string

GetCallDir 获取调用方法的文件目录.

func GetCallFile

func GetCallFile() string

GetCallFile 获取调用方法的文件路径.

func GetCallLine

func GetCallLine() int

GetCallLine 获取调用方法的行号.

func GetCallName

func GetCallName(f interface{}, onlyFun bool) string

GetCallName 获取调用的方法名称;f为目标方法;onlyFun为true时仅返回方法,不包括包名.

func GetCallPackage

func GetCallPackage(callFile ...string) string

GetCallPackage 获取调用方法或调用文件的包名.callFile为调用文件路径.

func GetCurrentPwd

func GetCurrentPwd() string

GetCurrentPwd 获取当前程序运行所在的路径,注意和Getwd有所不同. 若当前执行的是链接文件,则会指向真实二进制程序的所在目录.

func GetDatesBetweenDay

func GetDatesBetweenDay(startDate string, endDate string, format string) (day int64)

func GetDomain

func GetDomain(str string, isMain ...bool) string

GetDomain 从URL字符串中获取域名. 可选参数isMain,默认为false,取完整域名;为true时,取主域名(如abc.test.com取test.com).

func GetEleIndexesSlice

func GetEleIndexesSlice(slice interface{}, value interface{}) []int

func GetEleIndexesSliceE

func GetEleIndexesSliceE(slice interface{}, value interface{}) ([]int, error)

GetEleIndexesSliceE finds all indexes of the specified element in a slice.

func GetEndian

func GetEndian() binary.ByteOrder

getEndian 获取系统字节序类型,小端返回binary.LittleEndian,大端返回binary.BigEndian .

func GetEquationValue

func GetEquationValue(str, name string) (res string)

GetEquationValue 获取等式str中变量name的值.

func GetFieldValue

func GetFieldValue(arr interface{}, fieldName string) (res interface{}, err error)

GetFieldValue 获取(字典/结构体的)字段值;fieldName为字段名,大小写敏感.

func GetFileMode

func GetFileMode(fpath string) (os.FileMode, error)

GetFileMode 获取路径的权限模式.

func GetFileShaX

func GetFileShaX(fpath string, x uint16) (string, error)

ShaX 计算文件的 shaX 散列值,x为1/256/512.

func GetFuncNames

func GetFuncNames(val interface{}) (res []string)

GetFuncNames 获取变量的所有函数名.

func GetHostByIp

func GetHostByIp(ipAddress string) (string, error)

GetHostByIp 获取指定的IP地址对应的主机名.

func GetIPs

func GetIPs() (ips []string)

GetIPs 获取本机的IP列表.

func GetImageList

func GetImageList(s string) []string

func GetIntersectStrings

func GetIntersectStrings(minLen int, str1, str2 string) (res []string)

getIntersectStrings 获取两个字符串相同部分的切片. minLen为子串最小长度,为0则不限制.

func GetIpByHostname

func GetIpByHostname(hostname string) (string, error)

GetIpByHostname 返回主机名对应的 IPv4地址.

func GetIpsByDomain

func GetIpsByDomain(domain string) ([]string, error)

GetIpsByHost 获取互联网域名/主机名对应的 IPv4 地址列表.

func GetLongestSameString

func GetLongestSameString(str1, str2 string) (res string)

longestSameString 获取两个字符串最长相同的子串.

func GetMacAddrs

func GetMacAddrs() (macAddrs []string)

GetMacAddrs 获取本机的Mac网卡地址列表.

func GetMethod

func GetMethod(val interface{}, methodName string) interface{}

GetMethod 获取val结构体的methodName方法. 注意:返回的方法中的第一个参数是接收者. 所以,调用返回的方法时,必须将接收者作为第一个参数传递.

func GetMime

func GetMime(fpath string, fast bool) string

GetMime 获取文件mime类型;fast为true时根据后缀快速获取;为false时读取文件头获取.

func GetModTime

func GetModTime(fpath string) (res int64)

GetModTime 获取文件的修改时间戳,秒.

func GetPidByPort

func GetPidByPort(port int) (pid int)

GetPidByPort 根据端口号获取监听的进程PID. linux可能要求root权限; darwin依赖lsof; windows依赖netstat.

func GetProcessExecPath

func GetProcessExecPath(pid int) string

GetProcessExecPath 根据PID获取进程的执行路径.

func GetRandomSliceElem

func GetRandomSliceElem(i interface{}) interface{}

GetRandomSliceElem get a random element from a slice or array. If the length of slice or array is zero it will panic.

func GetTempDir

func GetTempDir() string

GetTempDir 返回用于临时文件的目录.

func GetTimeDate

func GetTimeDate(_format string) (date string)

func GetUrlParam

func GetUrlParam(_url string, _key string) (value string)

GetUrlParam 获取url中的参数(非解码)

func GetVariatePointerAddr

func GetVariatePointerAddr(val interface{}) int64

GetVariatePointerAddr 获取变量的指针地址.

func GetVariateType

func GetVariateType(v interface{}) string

GetVariateType 获取变量类型.

func Getcwd

func Getcwd() (string, error)

Getcwd 取得当前工作目录(程序可能在任务中进行多次目录切换).

func Getenv

func Getenv(varname string, defvalue ...string) string

Getenv 获取一个环境变量的值.defvalue为默认值.

func Gettype

func Gettype(variable interface{}) string

等价于PHP函数gettype()

func Glob

func Glob(pattern string, onlyNames bool) ([]string, error)

func Go added in v1.0.2

func Go(f func())

Go is an alternative to the go keyword, which is able to recover panic.

gopool.Go(func(arg interface{}){
    ...
}(nil))

func GoMemory

func GoMemory() uint64

MemoryGetUsage 获取当前go程序的内存使用,返回字节数.

func Gravatar

func Gravatar(email string, size uint16) string

Gravatar 获取Gravatar头像地址. email为邮箱;size为头像尺寸像素.

func HasChinese

func HasChinese(str string) bool

HasChinese 字符串是否含有中文.

func HasEmoji

func HasEmoji(str string) bool

HasEmoji 字符串是否含有表情符.

func HasEnglish

func HasEnglish(str string) bool

HasEnglish 是否含有英文字符,HasLetter的别名.

func HasFullWidth

func HasFullWidth(str string) bool

HasFullWidth 是否含有全角字符.

func HasHalfWidth

func HasHalfWidth(str string) bool

HasHalfWidth 是否含有半角字符.

func HasLetter

func HasLetter(str string) bool

HasLetter 字符串是否含有(英文)字母.

func HasMethod

func HasMethod(t interface{}, method string) bool

HasMethod 检查对象t是否具有method方法.

func HasSpecialChar

func HasSpecialChar(str string) bool

HasSpecialChar 字符串是否含有特殊字符.

func HasWhitespace

func HasWhitespace(str string) bool

HasWhitespace 是否带有空白字符.

func HashidsDecrypt

func HashidsDecrypt(salt string, minLength int, hash string) []int

解密

func HashidsEncrypt

func HashidsEncrypt(salt string, minLength int, params []int) string

加密

func HexToBin

func HexToBin(str string) (string, error)

SexToBin 将十六进制字符串转换为二进制字符串.

func HexToByte

func HexToByte(str string) ([]byte, error)

Hex2Byte 16进制字符串转字节切片.

func HexToDec

func HexToDec(str string) (int64, error)

HexToDec 将十六进制转换为十进制.

func HideCard

func HideCard(card string) string

HideCard 隐藏证件号码.

func HideMobile

func HideMobile(mobile string) string

HideMobile 隐藏手机号.

func HideTrueName

func HideTrueName(name string) string

HideTrueName 隐藏真实名称(如姓名、账号、公司等).

func Home

func Home() (dir string, err error)

func HomeDir

func HomeDir() (string, error)

HomeDir 获取当前用户的主目录.

func Hostname

func Hostname() (string, error)

Hostname 获取主机名.

func HourEnd

func HourEnd(t time.Time) time.Time

HourEnd time for given time

func HourStart

func HourStart(t time.Time) time.Time

HourStart time for given time

func Html2Text

func Html2Text(str string) string

Html2Text 将html转换为纯文本.

func Htmlentities

func Htmlentities(str string) string

Htmlentities 将字符转换为 HTML 转义字符.

func HtmlentityDecode

func HtmlentityDecode(str string) string

HtmlentityDecode 将HTML实体转换为它们对应的字符.

func HttpBuildQuery

func HttpBuildQuery(queryData url.Values) string

HttpBuildQuery 根据参数生成 URL-encode 之后的请求字符串.

func ImageDrawRGBA

func ImageDrawRGBA(img *image.RGBA, imgcode image.Image, x, y int)

将图片绘制到图片

func ImageDrawRGBAOffSet

func ImageDrawRGBAOffSet(img *image.RGBA, imgcode image.Image, r image.Rectangle, x, y int)

将图片绘制到图片

func ImageJPEG

func ImageJPEG(ph string) (image.Image, error)

读取JPEG图片返回image.Image对象

func ImagePNG

func ImagePNG(ph string) (image.Image, error)

读取PNG图片返回image.Image对象

func ImageRGBA

func ImageRGBA(width, height int) *image.RGBA

按照分辨率创建一张空白图片对象

func Img2Base64

func Img2Base64(fpath string) string

Img2Base64 将图片字节转换为base64字符串.imgType为图片扩展名.

func Implode

func Implode(delimiter string, arr interface{}) string

Implode 用delimiter将数组(数组/切片/字典/结构体)的值连接为一个字符串.

func InArray

func InArray(needle interface{}, haystack interface{}) bool

InArray 元素needle是否在数组haystack(切片/字典)内.

func InInt64Slice

func InInt64Slice(i int64, list []int64) bool

InInt64Slice 是否在64位整型切片内.

func InIntSlice

func InIntSlice(i int, list []int) bool

InIntSlice 是否在整型切片内.

func InRange

func InRange(value interface{}, left interface{}, right interface{}) bool

InRange 数值是否在某个范围内,将自动转换类型再比较.

func InRangeFloat32

func InRangeFloat32(value, left, right float32) bool

InRangeFloat32 数值是否在2个32位浮点数范围内.

func InRangeFloat64

func InRangeFloat64(value, left, right float64) bool

InRangeFloat64 数值是否在2个64位浮点数范围内.

func InRangeInt

func InRangeInt(value, left, right int) bool

InRangeInt 数值是否在2个整数范围内.

func InStringSlice

func InStringSlice(str string, list []string) bool

InStringSlice 是否在字符串切片内.

func Index

func Index(str, sub string, ignoreCase bool) int

Index 查找子串sub在字符串str中第一次出现的位置,不存在则返回-1; ignoreCase为是否忽略大小写.

func InsertInt16Slice

func InsertInt16Slice(src []int, index int, value int16) []int16

func InsertInt32Slice

func InsertInt32Slice(src []int, index int, value int32) []int32

func InsertInt64Slice

func InsertInt64Slice(src []int, index int, value int64) []int64

func InsertInt8Slice

func InsertInt8Slice(src []int8, index int, value int8) []int8

func InsertIntSlice

func InsertIntSlice(src []int, index, value int) []int

func InsertSliceE

func InsertSliceE(slice interface{}, index int, value interface{}) (interface{}, error)

InsertSliceE inserts a element to slice in the specified index. Note that the original slice will not be modified.

func InsertStrSlice

func InsertStrSlice(src []int, index int, value string) []string

func InsertUint16Slice

func InsertUint16Slice(src []int, index int, value uint16) []uint16

func InsertUint32Slice

func InsertUint32Slice(src []int, index int, value uint32) []uint32

func InsertUint64Slice

func InsertUint64Slice(src []int, index int, value uint64) []uint64

func InsertUint8Slice

func InsertUint8Slice(src []int8, index int, value uint8) []uint8

func InsertUintSlice

func InsertUintSlice(src []int, index int, value uint) []uint

func Int32ToInt64

func Int32ToInt64(_int int32) int64

func Int64ToInt32

func Int64ToInt32(_int int64) int32

func IntToString

func IntToString(val interface{}) string

IntToString int转string

func InterfaceToFloat

func InterfaceToFloat(val interface{}) (res float64)

InterfaceToFloat 强制将变量转换为浮点型. 数值类型将转为浮点型; 字符串将使用str2Float64; 布尔型的true为1.0,false为0; 数组、切片、字典、通道类型将取它们的长度; 指针、结构体类型为1.0,其他为0.

func InterfaceToInt

func InterfaceToInt(val interface{}) (res int)

InterfaceToInt 强制将变量转换为整型. 数值类型将转为整型; 字符串将使用str2Int; 布尔型的true为1,false为0; 数组、切片、字典、通道类型将取它们的长度; 指针、结构体类型为1,其他为0.

func InterfaceToString

func InterfaceToString(_array interface{}) string

func InvokeAttr

func InvokeAttr(object interface{}, attrName string) interface{}

func InvokeMethod

func InvokeMethod(object interface{}, methodName string, args ...interface{})

func Ip2Long

func Ip2Long(ipAddress string) uint32

Ip2Long 将 IPV4 的字符串互联网协议转换成长整型数字.

func IsASCII

func IsASCII(str string) bool

IsASCII 是否ASCII字符串.

func IsAlphaNumeric

func IsAlphaNumeric(str string) bool

IsAlphaNumeric 是否字母或数字.

func IsArray

func IsArray(variable interface{}) bool

等价于PHP函数is_array()

func IsBase64

func IsBase64(str string) bool

IsBase64 是否base64字符串.

func IsBase64Image

func IsBase64Image(str string) bool

IsBase64Image 是否base64编码的图片.

func IsBinary

func IsBinary(s string) bool

isBinary 字符串是否二进制.

func IsBinaryFile

func IsBinaryFile(fpath string) bool

IsBinary 是否二进制文件(且存在).

func IsBlank

func IsBlank(str string) bool

IsBlank 是否空(空白)字符串.

func IsBool

func IsBool(variable interface{}) bool

等价于PHP函数is_bool

func IsChinese

func IsChinese(str string) bool

IsChinese 字符串是否全部中文.

func IsChineseName

func IsChineseName(str string) bool

IsChineseName 字符串是否中文名称.

func IsContains

func IsContains(i interface{}, target interface{}) bool

IsContains checks whether slice or array contains the target element. Note that if the target element is a numeric literal, please specify its type explicitly, otherwise it defaults to int. For example you might call like IsContains([]int32{1,2,3}, int32(1)).

func IsCredit

func IsCredit(id string) byte

IsCredit计算身份证校验码,其中id为身份证号码.

func IsCreditNo

func IsCreditNo(str string) (bool, string)

IsCreditNo 检查是否(15或18位)身份证号码,并返回经校验的号码.

func IsDNSName

func IsDNSName(str string) bool

IsDNSName 是否DNS名称.

func IsDate2time

func IsDate2time(str string) (bool, int64)

func IsDialAddr

func IsDialAddr(str string) bool

IsDialAddr 是否网络拨号地址(形如127.0.0.1:80),用于net.Dial()检查.

func IsDir

func IsDir(path string) bool

func IsDouble

func IsDouble(variable interface{}) bool

等价于PHP函数is_double

func IsEmail

func IsEmail(email string, validateHost bool) (bool, error)

IsEmail 检查字符串是否邮箱.参数validateTrue,是否验证邮箱主机的真实性.

func IsEmpty

func IsEmpty(params interface{}) bool

func IsEnglish

func IsEnglish(str string, letterCase LkkCaseSwitch) bool

IsEnglish 字符串是否纯英文.letterCase是否检查大小写,枚举值(CASE_NONE,CASE_LOWER,CASE_UPPER).

func IsEqualArray

func IsEqualArray(arr1, arr2 interface{}) bool

IsEqualArray 两个数组/切片是否相同(不管元素顺序),且不会检查元素类型; arr1, arr2 是要比较的数组/切片.

func IsEqualMap

func IsEqualMap(arr1, arr2 interface{}) bool

IsEqualMap 两个字典是否相同(不管键顺序),且不会严格检查元素类型; arr1, arr2 是要比较的字典.

func IsEven

func IsEven(val int) bool

IsEven 变量是否偶数.

func IsExist

func IsExist(fpath string) bool

IsExist 路径(文件/目录)是否存在.

func IsFile

func IsFile(fpath string, ftype ...LkkFileType) (res bool)

IsFile 是否(某类型)文件,且存在. ftype为枚举(FILE_TYPE_ANY、FILE_TYPE_LINK、FILE_TYPE_REGULAR、FILE_TYPE_COMMON),默认FILE_TYPE_ANY;

func IsFloat

func IsFloat(variable interface{}) bool

is_double的别名

func IsGbk

func IsGbk(s []byte) (res bool)

IsGbk 字符串是否GBK编码.

func IsHex

func IsHex(str string) (res bool)

isHex 是否十六进制字符串.

func IsHexColor

func IsHexColor(str string) (bool, string)

IsHexColor 检查是否十六进制颜色,并返回带"#"的修正值.

func IsHost

func IsHost(str string) bool

IsHost 字符串是否主机名(IP或DNS名称).

func IsIP

func IsIP(str string) bool

IsIP 检查字符串是否IP地址.

func IsIPv4

func IsIPv4(str string) bool

IsIPv4 检查字符串是否IPv4地址.

func IsIPv6

func IsIPv6(str string) bool

IsIPv6 检查字符串是否IPv6地址.

func IsImg

func IsImg(fpath string) bool

IsImg 是否图片文件(仅检查后缀).

func IsInt

func IsInt(variable interface{}) bool

等价于PHP函数is_int

func IsInteger

func IsInteger(variable interface{}) bool

is_integer是is_int的别名

func IsInterface

func IsInterface(val interface{}) bool

IsInterface 变量是否接口.

func IsJSON

func IsJSON(str string) bool

IsJSON 字符串是否合法的json格式.

func IsLetters

func IsLetters(str string) bool

IsLetters 字符串是否全(英文)字母组成.

func IsLink(fpath string) bool

IsLink 是否链接文件(软链接,且存在).

func IsLinux

func IsLinux() bool

IsLinux 当前操作系统是否Linux.

func IsLittleEndian

func IsLittleEndian() bool

isLittleEndian 系统字节序类型是否小端存储.

func IsLong

func IsLong(variable interface{}) bool

is_long是is_int的别名

func IsLower

func IsLower(str string) bool

IsLower 字符串是否全部小写.

func IsMACAddr

func IsMACAddr(str string) bool

IsMACAddr 是否MAC物理网卡地址.

func IsMac

func IsMac() bool

IsMac 当前操作系统是否Mac OS/X.

func IsMap

func IsMap(val interface{}) bool

IsMap 检查变量是否字典.

func IsMd5

func IsMd5(str string) bool

IsMd5 是否md5值.

func IsMobilecn

func IsMobilecn(str string) bool

IsMobilecn 检查字符串是否中国大陆手机号.

func IsMultibyte

func IsMultibyte(str string) bool

IsMultibyte 字符串是否含有多字节字符.

func IsNan

func IsNan(val interface{}) bool

IsNan 是否为“非数值”.注意,这里复数也算“非数值”.

func IsNatural

func IsNatural(value float64) bool

IsNatural 数值是否为自然数(包括0).

func IsNaturalRange

func IsNaturalRange(arr []int, strict bool) (res bool)

IsNaturalRange 是否连续的自然数数组/切片,如[0,1,2,3...],其中不能有间断. strict为是否严格检查元素的顺序.

func IsNegative

func IsNegative(value float64) bool

IsNegative 数值是否为负数.

func IsNil

func IsNil(val interface{}) bool

IsNil 检查变量是否nil.

func IsNonNegative

func IsNonNegative(value float64) bool

IsNonNegative 数值是否为非负数.

func IsNonPositive

func IsNonPositive(value float64) bool

IsNonPositive 数值是否为非正数.

func IsNumeric

func IsNumeric(variable interface{}) bool

等价于PHP函数is_numeric

func IsOdd

func IsOdd(val int) bool

IsOdd 变量是否奇数.

func IsPhone

func IsPhone(str string) bool

IsPhone 是否电话号码(手机或固话).

func IsPointer

func IsPointer(val interface{}, notNil bool) (res bool)

IsPointer 检查变量是否指针类型; notNil 是否检查变量非nil.

func IsPortOpen

func IsPortOpen(host string, port interface{}, protocols ...string) bool

IsPortOpen 检查主机端口是否开放. host为主机名;port为(整型/字符串)端口号;protocols为协议名称,可选,默认tcp.

func IsPositive

func IsPositive(value float64) bool

IsPositive 数值是否为正数.

func IsPrivateIp

func IsPrivateIp(str string) (bool, error)

IsPrivateIp 是否私有IP地址(ipv4/ipv6).

func IsProcessExists

func IsProcessExists(pid int) (res bool)

IsProcessExists 进程是否存在.

func IsPublicIP

func IsPublicIP(str string) (bool, error)

IsPublicIP 是否公网IPv4.

func IsRgbColor

func IsRgbColor(str string) bool

IsRgbColor 检查字符串是否RGB颜色格式.

func IsRsaPublicKey

func IsRsaPublicKey(str string, keylen uint16) bool

IsRsaPublicKey 检查字符串是否RSA的公钥,keylen为密钥长度.

func IsSha1

func IsSha1(str string) bool

IsSha1 是否Sha1值.

func IsSha256

func IsSha256(str string) bool

IsSha256 是否Sha256值.

func IsSha512

func IsSha512(str string) bool

IsSha512 是否Sha512值.

func IsSlice

func IsSlice(val interface{}) bool

func IsString

func IsString(variable interface{}) bool

等价于PHP函数is_string

func IsStruct

func IsStruct(val interface{}) bool

IsStruct 检查变量是否结构体.

func IsTel

func IsTel(str string) bool

IsTel 是否固定电话或400/800电话.

func IsUpper

func IsUpper(str string) bool

IsUpper 字符串是否全部大写.

func IsUrl

func IsUrl(str string) bool

IsUrl 检查字符串是否URL.

func IsUrlExists

func IsUrlExists(str string) bool

IsUrlExists 检查URL是否存在.

func IsUtf8

func IsUtf8(s []byte) bool

IsUtf8 字符串是否UTF-8编码.

func IsWhitespaces

func IsWhitespaces(str string) bool

IsWhitespaces 是否全部空白字符,不包括空字符串.

func IsWhole

func IsWhole(value float64) bool

IsWhole 数值是否为整数.

func IsWindows

func IsWindows() bool

IsWindows 当前操作系统是否Windows.

func IsWord

func IsWord(str string) bool

IsWord 是否词语(不以下划线开头的中文、英文、数字、下划线).

func IsZip

func IsZip(fpath string) bool

IsZip 是否zip文件.

func JoinInts

func JoinInts(delimiter string, ints []int) (res string)

JoinInts 使用分隔符delimiter连接整数切片.

func JoinSliceWithSep

func JoinSliceWithSep(slice interface{}, sep string) string

JoinSliceWithSep joins all elements in slice with a separator

func JoinSliceWithSepE

func JoinSliceWithSepE(slice interface{}, sep string) (string, error)

JoinSliceWithSepE joins all elements in slice or array with separator and return an error if occurred.

func JoinStrings

func JoinStrings(delimiter string, strs []string) (res string)

JoinStrings 使用分隔符delimiter连接字符串切片strs.效率比Implode高.

func JsonDecode

func JsonDecode(_string string, _type interface{}) error

需要判断返回值,否则会出问题

func JsonEncode

func JsonEncode(v interface{}) string

func JsonFindFromFile

func JsonFindFromFile(fileName string, key string) (*gojsonq.Result, error)

func JsonFindFromStr

func JsonFindFromStr(jsonStr, key string) (*gojsonq.Result, error)

func JsonFromFile

func JsonFromFile(fileName string) *gojsonq.JSONQ

func JsonFromStr

func JsonFromStr(jsonStr string) *gojsonq.JSONQ

func JsonGetFromFile

func JsonGetFromFile(fileName string) (*gojsonq.Result, error)

func JsonGetFromStr

func JsonGetFromStr(jsonStr string) (*gojsonq.Result, error)

func JsonInit

func JsonInit() *gojsonq.JSONQ

func Jsonp2Json

func Jsonp2Json(str string) (string, error)

Jsonp2Json 将jsonp转为json串. Example: forbar({a:"1",b:2}) to {"a":"1","b":2}

func KafkaConsumer

func KafkaConsumer(brokerList []string, topic string, f func(msg *KafkaMessage))

func KafkaGroupConsumer

func KafkaGroupConsumer(brokerList []string, groupId string, topic string, f func(msg *KafkaMessage))

func KafkaProduct

func KafkaProduct(brokerList []string, topic string, message string) error

func LastIndex

func LastIndex(str, sub string, ignoreCase bool) int

LastIndex 查找子串sub在字符串str中最后一次出现的位置,不存在则返回-1; ignoreCase为是否忽略大小写.

func LcFirst

func LcFirst(_string string) string

func Lcfirst

func Lcfirst(str string) string

Lcfirst 将字符串的第一个字符转换为小写.

func Lcwords

func Lcwords(str string) string

Lcwords 将字符串中每个词的首字母转换为小写.

func LeftPad

func LeftPad(s string, padStr string, overallLen int) string

func LenArrayOrSlice

func LenArrayOrSlice(val interface{}, chkType uint8) int

lenArrayOrSlice 获取数组/切片的长度. chkType为检查类型,枚举值有(1仅数组,2仅切片,3数组或切片);结果为-1表示变量不是数组或切片,>=0表示合法长度.

func Levenshtein

func Levenshtein(a, b string) int

Levenshtein 计算两个字符串之间的编辑距离,返回值越小字符串越相似. 注意字符串最大长度为255.

func LoadConfig

func LoadConfig(configPath string)

加载配置,默认文件是app.toml 如果配置文件是app.toml,配置项是key,则可以直接获取key值 如果配置文件是other.toml,配置项是key,则通过other.key获取配置项 配置项一般加引号

func LocalIP

func LocalIP() (string, error)

LocalIP 获取本机第一个NIC's IP.

func Log

func Log(x, y float64) float64

Log 对数表达式,求以y为底x的对数.

func Long2Ip

func Long2Ip(properAddress uint32) string

Long2Ip 将长整型转化为字符串形式带点的互联网标准格式地址(IPV4).

func Ltrim

func Ltrim(str string, characterMask ...string) string

Ltrim 删除字符串开头的空白字符(或其他字符). characterMask为要修剪的字符.

func MapInterfaceToJson

func MapInterfaceToJson(_map map[string]interface{}) []byte

func MapInterfaceToString

func MapInterfaceToString(_map map[string]interface{}, _key string) string

MapInterfaceToString interface转string,针对map[string]interface{}的某个键

func MapString

func MapString(vs []string, f func(string) string) []string

func MatchEquations

func MatchEquations(str string) (res []string)

MatchEquations 匹配字符串中所有的等式.

func Max

func Max(nums ...interface{}) (res float64)

Max 取出任意类型中数值类型的最大值,无数值类型则为0.

func MaxFloat32Slice

func MaxFloat32Slice(sl []float32) float32

func MaxFloat64

func MaxFloat64(nums ...float64) (res float64)

MaxFloat64 64位浮点数序列求最大值.

func MaxFloat64Slice

func MaxFloat64Slice(sl []float64) float64

func MaxInt

func MaxInt(nums ...int) (res int)

MaxInt 整数序列求最大值.

func MaxInt16Slice

func MaxInt16Slice(sl []int16) int16

func MaxInt32Slice

func MaxInt32Slice(sl []int32) int32

func MaxInt64Slice

func MaxInt64Slice(sl []int64) int64

func MaxInt8Slice

func MaxInt8Slice(sl []int8) int8

func MaxIntSlice

func MaxIntSlice(sl []int) int

func MaxSliceE

func MaxSliceE(slice interface{}) (interface{}, error)

MaxSliceE returns the largest element of the slice and an error if occurred. If slice length is zero return the zero value of the element type.

func MaxUint16Slice

func MaxUint16Slice(sl []uint16) uint16

func MaxUint32Slice

func MaxUint32Slice(sl []uint32) uint32

func MaxUint64Slice

func MaxUint64Slice(sl []uint64) uint64

func MaxUint8Slice

func MaxUint8Slice(sl []uint8) uint8

func MaxUintSl

func MaxUintSl(sl []uint) uint

func MbStrlen

func MbStrlen(str string) int

MbStrlen 获取宽字符串的长度,多字节的字符被计为 1.

func MbSubstr

func MbSubstr(str string, start int, length ...int) string

MbSubstr 返回(宽字符)字符串str的子串. start 为起始位置.若值是负数,返回的结果将从 str 结尾处向前数第 abs(start) 个字符开始. length 为截取的长度.若值时负数, str 末尾处的 abs(length) 个字符将会被省略. start/length的绝对值必须<=原字符串长度.

func Md5

func Md5(str []byte) string

func MemoryUsage

func MemoryUsage(virtual bool) (used, free, total uint64)

MemoryUsage 获取内存使用率,单位字节. 参数 virtual(仅支持linux),是否取虚拟内存. used为已用, free为空闲, total为总数.

func MergeMap

func MergeMap(ss ...interface{}) map[interface{}]interface{}

MergeMap 合并字典,相同的键名时,后面的值将覆盖前一个值. ss是元素为字典的切片.

func MergeSlice

func MergeSlice(filterZero bool, ss ...interface{}) []interface{}

MergeSlice 合并一个或多个数组/切片. filterZero 是否过滤零值元素(nil,false,0,”,[]),true时排除零值元素,false时保留零值元素. ss是元素为数组/切片的切片.

func MethodExists

func MethodExists(val interface{}, methodName string) (bool, error)

MethodExists 检查val结构体中是否存在methodName方法.

func Min

func Min(nums ...interface{}) (res float64)

Min 取出任意类型中数值类型的最小值,无数值类型则为0.

func MinFloat32Slice

func MinFloat32Slice(sl []float32) float32

func MinFloat64

func MinFloat64(nums ...float64) (res float64)

MinFloat64 64位浮点数序列求最小值.

func MinFloat64Slice

func MinFloat64Slice(sl []float64) float64

func MinInt

func MinInt(nums ...int) (res int)

MinInt 整数序列求最小值.

func MinInt16Slice

func MinInt16Slice(sl []int16) int16

func MinInt32Slice

func MinInt32Slice(sl []int32) int32

func MinInt64Slice

func MinInt64Slice(sl []int64) int64

func MinInt8Slice

func MinInt8Slice(sl []int8) int8

func MinIntSlice

func MinIntSlice(sl []int) int

func MinSliceE

func MinSliceE(slice interface{}) (interface{}, error)

MinSliceE returns the smallest element of the slice and an error if occurred. If slice length is zero return the zero value of the element type.

func MinUint16Slice

func MinUint16Slice(sl []uint16) uint16

func MinUint32Slice

func MinUint32Slice(sl []uint32) uint32

func MinUint64Slice

func MinUint64Slice(sl []uint64) uint64

func MinUint8Slice

func MinUint8Slice(sl []uint8) uint8

func MinUintSlice

func MinUintSlice(sl []uint) uint

func Mkdir

func Mkdir(path string) error

func MonthEnd

func MonthEnd(t time.Time) time.Time

MonthEnd time for given time

func MonthStart

func MonthStart(t time.Time) time.Time

MonthStart time for given time

func Move

func Move(src string, dst string) error

func NearLogarithm

func NearLogarithm(num, base int, left bool) int

NearLogarithm 求以 base 为底 num 的对数临近值. num为自然数,base为正整数,left是否向左取整.

func NetHostname

func NetHostname() string

func NetIP

func NetIP() string

NetIP returns the primary IP address of the system or an empty string.

func NewStrMapItf

func NewStrMapItf() map[string]interface{}

NewStrMapItf 新建[字符-接口]字典.

func NewStrMapStr

func NewStrMapStr() map[string]string

NewStrMapStr 新建[字符-字符]字典.

func Nl2br

func Nl2br(str string) string

Nl2br 将换行符转换为br标签.

func Now

func Now() string

获取当前的时间 - 字符串

func NowAddDay

func NowAddDay(day int) time.Time

NowAddDay add some day time from now

func NowAddHour

func NowAddHour(hour int) time.Time

NowAddHour add some hour time from now

func NowAddMinutes

func NowAddMinutes(minutes int) time.Time

NowAddMinutes add some minutes time from now

func NowAddSeconds

func NowAddSeconds(seconds int) time.Time

NowAddSeconds add some seconds time from now

func NowHourStart

func NowHourStart() time.Time

NowHourStart time

func NowMilliUnix

func NowMilliUnix() int64

获取当前的时间 - 毫秒级时间戳

func NowNanoUnix

func NowNanoUnix() int64

获取当前的时间 - 纳秒级时间戳

func NowUnix

func NowUnix() int64

获取当前的时间 - Unix时间戳

func NumSign

func NumSign(value float64) (res int8)

NumSign 返回数值的符号.值>0为1,<0为-1,其他为0.

func NumberFormat

func NumberFormat(number float64, decimal uint8, point, thousand string) string

NumberFormat 以千位分隔符方式格式化一个数字. decimal为要保留的小数位数,point为小数点显示的字符,thousand为千位分隔符显示的字符. 有效数值是长度(包括小数点)为17位之内的数值,最后一位会四舍五入.

func NumericToFloat

func NumericToFloat(val interface{}) (res float64, err error)

numeric2Float 将数值转换为float64.

func OctToDec

func OctToDec(str string) (int64, error)

Oct2Dec 将八进制转换为十进制.

func Ord

func Ord(char string) rune

Ord 将首字符转换为rune(ASCII值). 注意:当字符串为空时返回65533.

func OutboundIP

func OutboundIP() (string, error)

OutboundIP 获取本机的出口IP.

func ParseStr

func ParseStr(encodedString string, result map[string]interface{}) error

ParseStr 将URI查询字符串转换为字典.

func ParseUrl

func ParseUrl(str string, component int16) (map[string]string, error)

ParseUrl 解析URL,返回其组成部分. component为需要返回的组成; -1: all; 1: scheme; 2: host; 4: port; 8: user; 16: pass; 32: path; 64: query; 128: fragment .

func PasswordSafeLevel

func PasswordSafeLevel(str string) (res uint8)

PasswordSafeLevel 检查密码安全等级;为0 极弱,为1 弱,为2 一般,为3 很好,为4 极佳.

func Pathinfo

func Pathinfo(fpath string, option int) map[string]string

Pathinfo 获取文件路径的信息. option为要返回的信息,枚举值如下: -1: all; 1: dirname; 2: basename; 4: extension; 8: filename; 若要查看某几项,则为它们之间的和.

func Percent

func Percent(val, total interface{}) float64

Percent 返回百分比((val/total) *100).

func Pkcs7Padding

func Pkcs7Padding(cipherText []byte, blockSize int, isZero bool) []byte

Pkcs7Padding PKCS7填充. cipherText为密文;blockSize为分组长度;isZero是否零填充.

func Pkcs7UnPadding

func Pkcs7UnPadding(origData []byte, blockSize int) []byte

Pkcs7UnPadding PKCS7拆解. origData为源数据;blockSize为分组长度.

func Post

func Post(url string, data interface{}, contentType string) string

发送POST请求 url: 请求地址 data: POST请求提交的数据 contentType: 请求体格式,如:application/json content: 请求放回的内容

func Pow

func Pow(x, y float64) float64

Pow 指数表达式,求x的y次方.

func PrivateCIDR

func PrivateCIDR() []*net.IPNet

PrivateCIDR 获取私有网段的CIDR(无类别域间路由).

func Pwd

func Pwd() string

func Quotemeta

func Quotemeta(str string) string

Quotemeta 转义元字符集,包括 . \ + * ? [ ^ ] ( $ )等.

func Rand

func Rand(min, max int) int

Rand RandInt的别名.

func RandFloat64

func RandFloat64(min, max float64) float64

RandFloat64 生成一个min~max范围内的随机float64浮点数.

func RandInt

func RandInt(min, max int) int

RandInt 生成一个min~max范围内的随机int整数.

func RandInt64

func RandInt64(min, max int64) int64

RandInt64 生成一个min~max范围内的随机int64整数.

func RandRange

func RandRange(_min int64, _max int64) int64

RandRange 获取指定范围内的可变随机整数数,正负都行。[a, b]

func RandString

func RandString(_length int64) string

RandString 生成指定长度的字符串

func Random

func Random(length uint8, rtype LkkRandString) string

Random 生成随机字符串. length为长度,rtype为枚举: RAND_STRING_ALPHA 字母; RAND_STRING_NUMERIC 数值; RAND_STRING_ALPHANUM 字母+数值; RAND_STRING_SPECIAL 字母+数值+特殊字符; RAND_STRING_CHINESE 仅中文.

func Range

func Range(start, end int) []int

Range 根据范围创建数组,包含指定的元素. start为起始元素值,end为末尾元素值.若start<end,返回升序的数组;若start>end,返回降序的数组.

func RawQueryGetParam

func RawQueryGetParam(rawquery, key string) (string, error)

RawQueryGetParam get the specified key parameter from query string rawquery is encoded query values without '?'. key is parameter name e.g. if query is "a=dog&b=tiger" and key is "a" will return dog

func RawQueryGetParams

func RawQueryGetParams(rawquery, key string) ([]string, error)

RawQueryGetParams get the specified key parameters from query string rawquery is encoded query values without '?'. key is parameter name e.g. if query is "a=dog&a=cat&b=tiger" and key is "a" will return [dog cat]

func RawURLAddParams

func RawURLAddParams(rawUrl string, params map[string]string) string

func RawURLDelParams

func RawURLDelParams(rawUrl string, keys []string) string

func RawURLGetAllParams

func RawURLGetAllParams(rawUrl string) (map[string][]string, error)

if rawUrl=http://www.google.com:8080/news/index.asp?boardID=520&page=1&page=2#name will get map[boardID:[520] page:[1 2]]

func RawURLGetParam

func RawURLGetParam(rawUrl, key string) (string, error)

if rawUrl=http://www.google.com:8080/news/index.asp?boardID=520&page=1&page=2#name and key="page" will get "1"

func RawURLGetParams

func RawURLGetParams(rawUrl, key string) ([]string, error)

if rawUrl=http://www.google.com:8080/news/index.asp?boardID=520&page=1&page=2#name and key=page will get [1 2]

func RawURLSetParams

func RawURLSetParams(rawUrl string, params map[string]string) string

func RawUrlDecode

func RawUrlDecode(str string) (string, error)

RawUrlDecode 对已编码的 URL 字符串进行解码.

func RawUrlEncode

func RawUrlEncode(str string) string

RawUrlEncode 按照 RFC 3986 对 URL 进行编码.

func RawUrlGetDomain

func RawUrlGetDomain(rawUrl string) string

if rawUrl=http://www.google.com:8080/news/index.asp?boardID=520&page=1&page=2#name will get www.google.com

func ReadFile

func ReadFile(fpath string) ([]byte, error)

ReadFile 读取文件内容.

func ReadFirstLine

func ReadFirstLine(fpath string) []byte

ReadFirstLine 读取文件首行.

func ReadInArray

func ReadInArray(fpath string) ([]string, error)

ReadInArray 把整个文件读入一个数组中,每行作为一个元素.

func ReadLastLine

func ReadLastLine(fpath string) []byte

ReadLastLine 读取文件末行.

func RealNetIP

func RealNetIP() string

RealNetIP returns the real local IP of the system or an empty string.

func RealPath

func RealPath(fpath string) string

RealPath 返回规范化的真实绝对路径名.path必须存在,若路径不存在则返回空字符串.

func ReferDownload

func ReferDownload(url string, site string, localFile string) string

func RegisterPool added in v1.0.2

func RegisterPool(p Pool) error

RegisterPool registers a new pool to the global map. GetPool can be used to get the registered pool by name. returns error if the same name is registered.

func Remove

func Remove(path string) error

func RemoveAfter

func RemoveAfter(str, after string, include, ignoreCase bool) string

RemoveAfter 移除after之后的字符串; include为是否移除包括after本身; ignoreCase为是否忽略大小写.

func RemoveBefore

func RemoveBefore(str, before string, include, ignoreCase bool) string

RemoveBefore 移除before之前的字符串; include为是否移除包括before本身; ignoreCase为是否忽略大小写.

func RemoveEmoji

func RemoveEmoji(str string) string

RemoveEmoji 移除字符串中的表情符(使用正则,效率较低).

func RemoveSpace

func RemoveSpace(str string, all bool) string

RemoveSpace 移除字符串中的空白字符. all为true时移除全部空白,为false时只替换连续的空白字符为一个空格.

func Rename

func Rename(oldname, newname string) error

Rename 重命名(或移动)文件/目录.

func Retry

func Retry(retryFunc RetryFunc, opts ...Option) error

Retry executes the retryFunc repeatedly until it was successful or canceled by the context The default times of retries is 5 and the default duration between retries is 3 seconds

func ReverseInt16Slice

func ReverseInt16Slice(src []int16) []int16

func ReverseInt32Slice

func ReverseInt32Slice(src []int32) []int32

func ReverseInt64Slice

func ReverseInt64Slice(src []int64) []int64

func ReverseInt8Slice

func ReverseInt8Slice(src []int8) []int8

func ReverseIntSlice

func ReverseIntSlice(src []int) []int

func ReverseSliceE

func ReverseSliceE(slice interface{}) (interface{}, error)

ReverseSliceE reverses the specified slice without modifying the original slice.

func ReverseStrSlice

func ReverseStrSlice(src []string) []string

func ReverseUint16Slice

func ReverseUint16Slice(src []uint16) []uint16

func ReverseUint32Slice

func ReverseUint32Slice(src []uint32) []uint32

func ReverseUint64Slice

func ReverseUint64Slice(src []uint64) []uint64

func ReverseUint8Slice

func ReverseUint8Slice(src []uint8) []uint8

func ReverseUintSlice

func ReverseUintSlice(src []uint) []uint

func RightPad

func RightPad(s string, padStr string, overallLen int) string

func Round

func Round(value float64) float64

Round 对浮点数(的整数)进行四舍五入.

func RoundPlus

func RoundPlus(value float64, precision uint8) float64

RoundPlus 对指定的小数位进行四舍五入. precision为小数位数.

func RoundedFixed

func RoundedFixed(val float64, n int) float64

小数点后 n 位 - 四舍五入

func RsaPrivateDecrypt

func RsaPrivateDecrypt(decryptStr string, path string) (string, error)

私钥解密

func RsaPublicEncrypt

func RsaPublicEncrypt(encryptStr string, path string) (string, error)

公钥加密

func Rtrim

func Rtrim(str string, characterMask ...string) string

Rtrim 删除字符串末端的空白字符(或者其他字符). characterMask为要修剪的字符.

func RunesToBytes

func RunesToBytes(rs []rune) []byte

runes2Bytes 将[]rune转为[]byte.

func SBC2DBC

func SBC2DBC(s string) string

SBC2DBC 全角转半角.

func SafeFileName

func SafeFileName(str string) string

SafeFileName 将文件名转换为安全可用的字符串.

func Schedule

func Schedule(d time.Duration, fn interface{}, args ...interface{}) chan bool

Schedule invoke function every duration time, util close the returned bool chan

func Serialize

func Serialize(val interface{}) ([]byte, error)

Serialize 对变量进行序列化.

func ServiceStartime

func ServiceStartime() int64

ServiceStartime 获取当前服务启动时间戳,秒.

func ServiceUptime

func ServiceUptime() time.Duration

ServiceUptime 获取当前服务运行时间,纳秒int64.

func SetPanicHandler added in v1.0.2

func SetPanicHandler(f func(context.Context, interface{}))

SetPanicHandler sets the panic handler for the global pool.

func SetPoolCap added in v1.0.2

func SetPoolCap(cap int32)

SetCap is not recommended to be called, this func changes the global pool's capacity which will affect other callers.

func Setenv

func Setenv(varname, data string) error

Setenv 设置一个环境变量的值.

func ShaX

func ShaX(str string, x uint16) string

ShaX 计算字符串的 shaX 散列值,x为1/256/512 .

func ShaXByte

func ShaXByte(str []byte, x uint16) []byte

shaXByte 计算字节切片的 shaX 散列值,x为1/256/512.

func Shuffle

func Shuffle(str string) string

Shuffle 随机打乱字符串.

func SimilarText

func SimilarText(str1, str2 string, len1, len2 int) int

SimilarText 计算两个字符串的相似度;返回在两个字符串中匹配字符的数目,以及相似程度百分数.

func Sleep

func Sleep(t int64)

Sleep 延缓执行,秒.

func SliceFill

func SliceFill(val interface{}, num int) []interface{}

SliceFill 用给定的值val填充切片,num为插入元素的数量.

func SlicePop

func SlicePop(s *[]interface{}) interface{}

SlicePop 弹出切片最后一个元素(出栈),并返回该元素.

func SlicePush

func SlicePush(s *[]interface{}, elements ...interface{}) int

SlicePush 将一个或多个元素压入切片的末尾(入栈),返回处理之后切片的元素个数.

func SliceShift

func SliceShift(s *[]interface{}) interface{}

SliceShift 将切片开头的元素移出,并返回该元素.

func SliceUnshift

func SliceUnshift(s *[]interface{}, elements ...interface{}) int

SliceUnshift 在切片开头插入一个或多个元素,返回处理之后切片的元素个数.

func SplitNaturalNum

func SplitNaturalNum(num, base int) []int

SplitNaturalNum 将自然数 num 按底数 base 进行拆解.

func StartsWith

func StartsWith(str, sub string, ignoreCase bool) bool

StartsWith 字符串str是否以sub开头.

func StartsWiths

func StartsWiths(str string, subs []string, ignoreCase bool) (res bool)

StartsWiths 字符串str是否以subs其中之一为开头.

func Stat

func Stat(path string) (os.FileInfo, error)

func Str2Timestamp

func Str2Timestamp(str string, format ...string) (int64, error)

Str2Timestamp 将字符串转换为时间戳,秒. str 为要转换的字符串; format 为该字符串的格式,默认为"2006-01-02 15:04:05" .

func Str2Timestruct

func Str2Timestruct(str string, format ...string) (time.Time, error)

Str2Timestruct 将字符串转换为时间结构. str 为要转换的字符串; format 为该字符串的格式,默认为"2006-01-02 15:04:05" .

func StringFilterInput

func StringFilterInput(_value string) string

StringFilterInput 过滤Input输入的值 转义%、"、'、(、)、!、/、^、*、.、

func StringFormatBigInt

func StringFormatBigInt(mem uint64) string

func StringHideValue

func StringHideValue(_string string, start int, end int, replaceValue string) string

StringHideValue 隐藏/替换字符串中的某些字符 如隐藏手机号:185*******6,调用Common.HideStringValue("18511111111", 3, 10, "*")

func StringReplace

func StringReplace(text string, _old string, _new string) string

func StringReplaceMulti

func StringReplaceMulti(str string, fromTo ...string) string

func StringReplaceRange

func StringReplaceRange(text string, _start int, _end int, _new string) string

func StringReverse

func StringReverse(str string) string

StringReverse 反转字符串.

func StringToBool

func StringToBool(val string) (res bool)

str2Bool 将字符串转换为布尔值. 1, t, T, TRUE, true, True 等字符串为真; 0, f, F, FALSE, false, False 等字符串为假.

func StringToByte

func StringToByte(_str string) []byte

func StringToByteFast

func StringToByteFast(_str string) (_byte []byte)

func StringToFloat

func StringToFloat(_str string) float64

StringToFloat string转float

func StringToInt

func StringToInt(_str string) int64

StringToInt string转int

func StringToRunes

func StringToRunes(val string) []rune

StringToRunes 字符串转为字符切片.

func StringToUTF8

func StringToUTF8(cont, srcEncoding string) (str string, err error)

StringToUTF8 将指定字符编码的字符串转为utf8

func StripTags

func StripTags(str string) string

StripTags 过滤html标签.

func Stripos

func Stripos(haystack, needle string, offset int) int

Stripos 查找字符串首次出现的位置(不区分大小写),找不到时返回-1. haystack在该字符串中进行查找,needle要查找的字符串; offset起始位置,为负数时时,搜索会从字符串结尾指定字符数开始.

func Stripslashes

func Stripslashes(str string) string

Stripslashes 反引用一个引用字符串.

func Strlen

func Strlen(str string) int

Strlen 获取字符串长度.

func Strpad

func Strpad(str string, fill string, max int, ptype LkkPadType) string

Strpad 使用fill填充str字符串到指定长度max. ptype为填充类型,枚举值(PAD_LEFT,PAD_RIGHT,PAD_BOTH).

func StrpadBoth

func StrpadBoth(str string, fill string, max int) string

StrpadBoth 字符串两侧填充,请参考Strpad.

func StrpadLeft

func StrpadLeft(str string, fill string, max int) string

StrpadLeft 字符串左侧填充,请参考Strpad.

func StrpadRight

func StrpadRight(str string, fill string, max int) string

StrpadRight 字符串右侧填充,请参考Strpad.

func Strpos

func Strpos(haystack, needle string, offset int) int

Strpos 查找字符串首次出现的位置,找不到时返回-1. haystack在该字符串中进行查找,needle要查找的字符串; offset起始位置,为负数时时,搜索会从字符串结尾指定字符数开始.

func Strripos

func Strripos(haystack, needle string, offset int) int

Strripos 查找指定字符串在目标字符串中最后一次出现的位置(不区分大小写).

func Strrpos

func Strrpos(haystack, needle string, offset int) int

Strrpos 查找指定字符串在目标字符串中最后一次出现的位置.

func StructToMap

func StructToMap(obj interface{}) map[string]interface{}

@: 利用反射将结构体转化为map

func Substr

func Substr(str string, start int, length ...int) string

Substr 截取字符串str的子串. start 为起始位置.若值是负数,返回的结果将从 str 结尾处向前数第 abs(start) 个字符开始. length 为截取的长度.若值时负数, str 末尾处的 abs(length) 个字符将会被省略. start/length的绝对值必须<=原字符串长度.

func SubstrCount

func SubstrCount(str, substr string) int

SubstrCount 计算子串substr在字符串str中出现的次数,区分大小写.

func SubstriCount

func SubstriCount(str, substr string) int

SubstriCount 计算子串substr在字符串str中出现的次数,忽略大小写.

func Sum

func Sum(nums ...interface{}) (res float64)

Sum 对任意类型序列中的数值类型求和,忽略非数值的.

func SumFloat64

func SumFloat64(nums ...float64) float64

SumFloat64 浮点数求和.

func SumInt

func SumInt(nums ...int) int

SumInt 整数求和.

func SumSlice

func SumSlice(slice interface{}) float64

SumSlice calculates the sum of slice elements

func SumSliceE

func SumSliceE(slice interface{}) (float64, error)

SumSliceE returns the sum of slice elements and an error if occurred.

func System

func System(command string) (retInt int, outStr, errStr []byte)

System 与Exec相同,但会同时打印标准输出和标准错误.

func TarGz

func TarGz(src string, dstTar string, ignorePatterns ...string) (bool, error)

TarGz 打包压缩tar.gz. src为源文件或目录,dstTar为打包的路径名,ignorePatterns为要忽略的文件正则.

func TempDir

func TempDir(names ...string) string

func TimeConvertToLayout

func TimeConvertToLayout(template string) string

ToLayout convert date template to go time layout

Template Vars:

Y,y - year
 Y - year 2006
 y - year 06
M,m - month 01
D,d - day 02
H,h - hour 15
I,i - minute 04
S,s - second 05

func ToCamelCase

func ToCamelCase(str string) string

ToCamelCase 转为驼峰写法. 去掉包括下划线"_"和横杠"-".

func ToKebabCase

func ToKebabCase(str string) string

ToSnakeCase 转为串形写法. 使用横杠"-"连接.

func ToSnakeCase

func ToSnakeCase(str string) string

ToSnakeCase 转为蛇形写法. 使用下划线"_"连接.

func ToString

func ToString(val interface{}) string

toStr 强制将变量转换为字符串.

func TodayEnd

func TodayEnd() time.Time

TodayEnd time

func TodayStart

func TodayStart() time.Time

TodayStart time

func Touch

func Touch(fpath string, size int64) bool

Touch 快速创建指定大小的文件,size为字节.

func TriggerGC

func TriggerGC()

TriggerGC 触发GC(非阻塞).

func Trim

func Trim(str string, characterMask ...string) string

Trim 去除字符串首尾处的空白字符(或者其他字符). characterMask为要修剪的字符.

func TrimBOM

func TrimBOM(str []byte) []byte

TrimBOM 移除字符串中的BOM

func TruncRound

func TruncRound(val float64, n int) float64

小数点后 n 位 - 舍去

func UcFirst

func UcFirst(_string string) string

func Ucfirst

func Ucfirst(str string) string

Ucfirst 将字符串的第一个字符转换为大写.

func Ucwords

func Ucwords(str string) string

Ucwords 将字符串中每个词的首字母转换为大写.

func UnSerialize

func UnSerialize(data []byte, register ...interface{}) (val interface{}, err error)

UnSerialize 对字符串进行反序列化. 其中register注册对象,其类型必须和Serialize的一致.

func UnTarGz

func UnTarGz(srcTar, dstDir string) (bool, error)

UnTarGz 将tar.gz文件解压缩. srcTar为压缩包,dstDir为解压目录.

func UnZip

func UnZip(srcZip, dstDir string) (bool, error)

UnZip 解压zip文件.srcZip为zip文件路径,dstDir为解压目录.

func Uniqid

func Uniqid(prefix string) string

Uniqid 获取一个带前缀的唯一ID(24位). prefix 为前缀字符串.

func Unique64Ints

func Unique64Ints(ints []int64) (res []int64)

Unique64Ints 移除64位整数切片中的重复值.

func UniqueFloat32Slice

func UniqueFloat32Slice(src []float32) []float32

func UniqueFloat64Slice

func UniqueFloat64Slice(src []float64) []float64

func UniqueInt16Slice

func UniqueInt16Slice(src []int16) []int16

func UniqueInt32Slice

func UniqueInt32Slice(src []int32) []int32

func UniqueInt64Slice

func UniqueInt64Slice(src []int64) []int64

func UniqueInt8Slice

func UniqueInt8Slice(src []int8) []int8

func UniqueIntSlice

func UniqueIntSlice(src []int) []int

func UniqueInts

func UniqueInts(ints []int) (res []int)

UniqueInts 移除整数切片中的重复值.

func UniqueSliceE

func UniqueSliceE(slice interface{}) (interface{}, error)

UniqueSliceE deletes repeated elements in a slice with error. Note that the original slice will not be modified.

func UniqueStrSlice

func UniqueStrSlice(src []string) []string

func UniqueStrings

func UniqueStrings(strs []string) (res []string)

UniqueStrings 移除字符串切片中的重复值.

func UniqueUint16Slice

func UniqueUint16Slice(src []uint16) []uint16

func UniqueUint32Slice

func UniqueUint32Slice(src []uint32) []uint32

func UniqueUint64Slice

func UniqueUint64Slice(src []uint64) []uint64

func UniqueUint8Slice

func UniqueUint8Slice(src []uint8) []uint8

func UniqueUintSlice

func UniqueUintSlice(src []uint) []uint
func Unlink(fpath string) error

Unlink 删除文件.

func Unsetenv

func Unsetenv(varname string) error

Unsetenv 删除一个环境变量.

func UpdateInt16Slice

func UpdateInt16Slice(src []int, index int, value int16) []int16

func UpdateInt32Slice

func UpdateInt32Slice(src []int, index int, value int32) []int32

func UpdateInt64Slice

func UpdateInt64Slice(src []int, index int, value int64) []int64

func UpdateInt8Slice

func UpdateInt8Slice(src []int8, index int, value int8) []int8

func UpdateIntSlice

func UpdateIntSlice(src []int, index, value int) []int

func UpdateSliceE

func UpdateSliceE(slice interface{}, index int, value interface{}) (interface{}, error)

UpdateSliceE modifies the specified index element of slice. Note that the original slice will not be modified.

func UpdateStrSlice

func UpdateStrSlice(src []int, index int, value string) []string

func UpdateUint16Slice

func UpdateUint16Slice(src []int, index int, value uint16) []uint16

func UpdateUint32Slice

func UpdateUint32Slice(src []int, index int, value uint32) []uint32

func UpdateUint64Slice

func UpdateUint64Slice(src []int, index int, value uint64) []uint64

func UpdateUint8Slice

func UpdateUint8Slice(src []int8, index int, value uint8) []uint8

func UpdateUintSlice

func UpdateUintSlice(src []int, index int, value uint) []uint

func Uptime

func Uptime() (uint64, error)

Uptime 获取系统运行时间,秒.

func UrlDecode

func UrlDecode(str string) (string, error)

UrlDecode 解码已编码的 URL 字符串.

func UrlEncode

func UrlEncode(str string) string

UrlEncode 编码 URL 字符串.

func Usleep

func Usleep(t int64)

Usleep 以指定的微秒数延迟执行.

func Utf8ToBig5

func Utf8ToBig5(s []byte) ([]byte, error)

Utf8ToBig5 UTF-8转BIG5编码.

func Utf8ToGbk

func Utf8ToGbk(s []byte) ([]byte, error)

Utf8ToGbk UTF-8转GBK编码.

func UuidV4

func UuidV4() (string, error)

UuidV4 获取36位UUID(Version4,RFC4122).

func UuidV5

func UuidV5(name, namespace []byte) (string, error)

UuidV5 根据提供的字符,使用sha1生成36位哈希值(Version5,RFC4122); name为要计算散列值的字符,可以为nil; namespace为命名空间,长度必须为16.

func ValueInterfaceToString

func ValueInterfaceToString(value interface{}) string

ValueInterfaceToString interface转string,非map[string]interface{}

func VerifyFunc

func VerifyFunc(f interface{}, args ...interface{}) (vf reflect.Value, vargs []reflect.Value, err error)

VerifyFunc 验证是否函数,并且参数个数、类型是否正确. 返回有效的函数、有效的参数.

func VersionCompare

func VersionCompare(version1, version2, operator string) (bool, error)

VersionCompare 对比两个版本号字符串. operator允许的操作符有: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne . 特定的版本字符串,将会用以下顺序处理: 无 < dev < alpha = a < beta = b < RC = rc < # < pl = p < ga < release = r 用法: VersionCompare("1.2.3-alpha", "1.2.3RC7", '>=') ; VersionCompare("1.2.3-beta", "1.2.3pl", 'lt') ; VersionCompare("1.1_dev", "1.2any", 'eq') .

func WrapError

func WrapError(err error, args ...interface{}) (res error)

WrapError 错误包裹.

func YearEnd

func YearEnd(t time.Time) time.Time

YearEnd time for given time

func YearStart

func YearStart(t time.Time) time.Time

YearStart time for given time

func ZeroPadding

func ZeroPadding(cipherText []byte, blockSize int) []byte

zeroPadding PKCS7使用0填充.

func ZeroUnPadding

func ZeroUnPadding(origData []byte) []byte

zeroUnPadding PKCS7-0拆解.

func Zip

func Zip(dst string, fpaths ...string) (bool, error)

Zip 将文件或目录进行zip打包.fpaths为源文件或目录的路径.

Types

type BiosInfo

type BiosInfo struct {
	Vendor  string `json:"vendor"`
	Version string `json:"version"`
	Date    string `json:"date"`
}

BiosInfo BIOS信息

func GetBiosInfo

func GetBiosInfo() *BiosInfo

GetBiosInfo 获取BIOS信息. 注意:Mac机器没有BIOS信息,它使用EFI.

type BoardInfo

type BoardInfo struct {
	Name     string `json:"name"`
	Vendor   string `json:"vendor"`
	Version  string `json:"version"`
	Serial   string `json:"serial"`
	AssetTag string `json:"assettag"`
}

BoardInfo Board信息

func GetBoardInfo

func GetBoardInfo() *BoardInfo

GetBoardInfo 获取Board信息.

type CMPRES

type CMPRES int8
const (
	INCMP CMPRES = iota - 2
	LT
	EQ
	GT
)

func Compare

func Compare(lhs, rhs interface{}) CMPRES

Compare compare the size relationship between two numeric values or strings. The result is INCMP(incomparable), LT(less than), EQ(equal) or GT(greater than).

type CallBack

type CallBack func()

CallBack 回调执行函数,无参数且无返回值

type Config

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

func (*Config) Get

func (c *Config) Get(keyname string) interface{}

get 一个原始值

func (*Config) GetBool

func (c *Config) GetBool(keyname string) bool

getbool

func (*Config) GetDuration

func (c *Config) GetDuration(keyname string) time.Duration

GetDuration

func (*Config) GetFloat64

func (c *Config) GetFloat64(keyname string) float64

float64

func (*Config) GetFloat64ByDefault

func (c *Config) GetFloat64ByDefault(keyname string, value float64) float64

func (*Config) GetInt

func (c *Config) GetInt(keyname string) int

getint

func (*Config) GetInt32

func (c *Config) GetInt32(keyname string) int32

getint32

func (*Config) GetInt32ByDefault

func (c *Config) GetInt32ByDefault(keyname string, value int32) int32

func (*Config) GetInt64

func (c *Config) GetInt64(keyname string) int64

getint64

func (*Config) GetInt64ByDefault

func (c *Config) GetInt64ByDefault(keyname string, value int64) int64

func (*Config) GetIntByDefault

func (c *Config) GetIntByDefault(keyname string, value int) int

func (*Config) GetString

func (c *Config) GetString(keyname string) string

getstring

func (*Config) GetStringByDefault

func (c *Config) GetStringByDefault(keyname string, value string) string

func (*Config) GetStringMap

func (c *Config) GetStringMap(keyname string) map[string]interface{}

GetStringMap

func (*Config) GetStringMapString

func (c *Config) GetStringMapString(keyname string) map[string]string

GetStringMapString

func (*Config) GetStringSlice

func (c *Config) GetStringSlice(keyname string) []string

GetStringSlice

type CpuInfo

type CpuInfo struct {
	Vendor  string `json:"vendor"`
	Model   string `json:"model"`
	Speed   string `json:"speed"`   // CPU clock rate in MHz
	Cache   uint   `json:"cache"`   // CPU cache size in KB
	Cpus    uint   `json:"cpus"`    // number of physical CPUs
	Cores   uint   `json:"cores"`   // number of physical CPU cores
	Threads uint   `json:"threads"` // number of logical (HT) CPU cores
}

CpuInfo CPU信息

func GetCpuInfo

func GetCpuInfo() *CpuInfo

GetCpuInfo 获取CPU信息.

type FileFilter

type FileFilter func(string) bool

FileFilter 文件过滤函数

type Fn

type Fn func(...interface{}) interface{}

Fn is for curry function which is func(...interface{}) interface{}

func (Fn) Curry

func (f Fn) Curry(i interface{}) func(...interface{}) interface{}

Curry make a curry function

type KafkaGroupMessage

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

func (KafkaGroupMessage) Cleanup

func (KafkaGroupMessage) ConsumeClaim

func (KafkaGroupMessage) Setup

type KafkaMessage

type KafkaMessage struct {
	*sarama.ConsumerMessage
}

type LkkArrCompareType

type LkkArrCompareType uint8

LkkArrCompareType 枚举类型,数组比较方式

type LkkCaseSwitch

type LkkCaseSwitch uint8

LkkCaseSwitch 枚举类型,大小写开关

type LkkFileCover

type LkkFileCover int8

LkkFileCover 枚举类型,文件是否覆盖

type LkkFileTree

type LkkFileTree uint8

LkkFileTree 枚举类型,文件树查找类型

type LkkFileType

type LkkFileType uint8

LkkFileType 枚举类型,文件类型

type LkkPKCSType

type LkkPKCSType int8

LkkPKCSType 枚举类型,PKCS填充类型

type LkkPadType

type LkkPadType uint8

LkkPadType 枚举类型,字符串填充类型

type LkkRandString

type LkkRandString uint8

LkkRandString 枚举类型,随机字符串类型

type Option

type Option func(*RetryConfig)

Option is for adding retry config

func Context

func Context(ctx context.Context) Option

Context set retry context config

func RetryDuration

func RetryDuration(d time.Duration) Option

RetryDuration set duration of retries

func RetryTimes

func RetryTimes(n uint) Option

RetryTimes set times of retry

type Pool added in v1.0.2

type Pool interface {
	// Name returns the corresponding pool name.
	Name() string
	// SetCap sets the goroutine capacity of the pool.
	SetCap(cap int32)
	// Go executes f.
	Go(f func())
	// CtxGo executes f and accepts the context.
	CtxGo(ctx context.Context, f func())
	// SetPanicHandler sets the panic handler.
	SetPanicHandler(f func(context.Context, interface{}))
}

func GetPool added in v1.0.2

func GetPool(name string) Pool

GetPool gets the registered pool by name. Returns nil if not registered.

func NewPool added in v1.0.2

func NewPool(name string, cap int32, config *PoolConfig) Pool

NewPool creates a new pool with the given name, cap and config.

type PoolConfig added in v1.0.2

type PoolConfig struct {
	// threshold for scale.
	// new goroutine is created if len(task chan) > ScaleThreshold.
	// defaults to defaultScalaThreshold.
	ScaleThreshold int32
}

GoConfig is used to config pool.

func NewPoolConfig added in v1.0.2

func NewPoolConfig() *PoolConfig

NewGoConfig creates a default GoConfig.

type RetryConfig

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

RetryConfig is config for retry

type RetryFunc

type RetryFunc func() error

RetryFunc is function that retry executes

type StringBuilder

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

func (*StringBuilder) Bool

func (s *StringBuilder) Bool(value bool) *StringBuilder

func (*StringBuilder) Byte

func (s *StringBuilder) Byte(value byte) *StringBuilder

func (*StringBuilder) Bytes

func (s *StringBuilder) Bytes() []byte

func (*StringBuilder) Float

func (s *StringBuilder) Float(value float64) *StringBuilder

func (*StringBuilder) Int

func (s *StringBuilder) Int(value int) *StringBuilder

func (*StringBuilder) Printf

func (s *StringBuilder) Printf(format string, args ...interface{}) *StringBuilder

func (*StringBuilder) String

func (s *StringBuilder) String() string

func (*StringBuilder) Uint

func (s *StringBuilder) Uint(value uint) *StringBuilder

func (*StringBuilder) Write

func (s *StringBuilder) Write(strings ...string) *StringBuilder

func (*StringBuilder) WriteBytes

func (s *StringBuilder) WriteBytes(bytes []byte) *StringBuilder

func (*StringBuilder) WriteTo

func (s *StringBuilder) WriteTo(writer io.Writer) (n int64, err error)

type SyncBool

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

func NewSyncBool

func NewSyncBool(value bool) *SyncBool

func (*SyncBool) Get

func (s *SyncBool) Get() bool

func (*SyncBool) Invert

func (s *SyncBool) Invert() bool

func (*SyncBool) Set

func (s *SyncBool) Set(value bool)

func (*SyncBool) Swap

func (s *SyncBool) Swap(value bool) bool

type SyncFloat

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

func NewSyncFloat

func NewSyncFloat(value float64) *SyncFloat

func (*SyncFloat) Add

func (s *SyncFloat) Add(value float64) float64

func (*SyncFloat) Get

func (s *SyncFloat) Get() float64

func (*SyncFloat) Mul

func (s *SyncFloat) Mul(value float64) float64

func (*SyncFloat) Set

func (s *SyncFloat) Set(value float64)

func (*SyncFloat) Swap

func (s *SyncFloat) Swap(value float64) float64

type SyncInt

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

func NewSyncInt

func NewSyncInt(value int) *SyncInt

func (*SyncInt) Add

func (s *SyncInt) Add(value int) int

func (*SyncInt) Get

func (s *SyncInt) Get() int

func (*SyncInt) Mul

func (s *SyncInt) Mul(value int) int

func (*SyncInt) Set

func (s *SyncInt) Set(value int)

func (*SyncInt) Swap

func (s *SyncInt) Swap(value int) int

type SyncMap

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

func NewSyncMap

func NewSyncMap() *SyncMap

func (*SyncMap) Add

func (s *SyncMap) Add(key string, value interface{})

func (*SyncMap) AddBool

func (s *SyncMap) AddBool(key string, value bool)

func (*SyncMap) AddFloat

func (s *SyncMap) AddFloat(key string, value float64)

func (*SyncMap) AddInt

func (s *SyncMap) AddInt(key string, value int)

func (*SyncMap) AddString

func (s *SyncMap) AddString(key string, value string)

func (*SyncMap) Bool

func (s *SyncMap) Bool(key string) *SyncBool

func (*SyncMap) Delete

func (s *SyncMap) Delete(key string)

func (*SyncMap) Float

func (s *SyncMap) Float(key string) *SyncFloat

func (*SyncMap) Get

func (s *SyncMap) Get(key string) interface{}

func (*SyncMap) Has

func (s *SyncMap) Has(key string) bool

func (*SyncMap) Int

func (s *SyncMap) Int(key string) *SyncInt

func (*SyncMap) String

func (s *SyncMap) String(key string) *SyncString

type SyncPoolMap

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

func NewSyncPoolMap

func NewSyncPoolMap() *SyncPoolMap

func (*SyncPoolMap) Add

func (s *SyncPoolMap) Add(key string, value *sync.Pool)

func (*SyncPoolMap) Delete

func (s *SyncPoolMap) Delete(key string)

func (*SyncPoolMap) Get

func (s *SyncPoolMap) Get(key string) *sync.Pool

func (*SyncPoolMap) GetOrAddNew

func (s *SyncPoolMap) GetOrAddNew(key string, newFunc func() interface{}) *sync.Pool

func (*SyncPoolMap) Has

func (s *SyncPoolMap) Has(key string) bool

type SyncString

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

func NewSyncString

func NewSyncString(value string) *SyncString

func (*SyncString) Append

func (s *SyncString) Append(value string) string

func (*SyncString) Get

func (s *SyncString) Get() string

func (*SyncString) Set

func (s *SyncString) Set(value string)

func (*SyncString) Swap

func (s *SyncString) Swap(value string) string

type SyncStringMap

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

func NewSyncStringMap

func NewSyncStringMap() *SyncStringMap

func (*SyncStringMap) Add

func (s *SyncStringMap) Add(key string, value string)

func (*SyncStringMap) Delete

func (s *SyncStringMap) Delete(key string)

func (*SyncStringMap) Get

func (s *SyncStringMap) Get(key string) string

func (*SyncStringMap) Has

func (s *SyncStringMap) Has(key string) bool

type SystemInfo

type SystemInfo struct {
	ServerName   string  `json:"server_name"`    //服务器名称
	SystemArch   string  `json:"system_arch"`    //系统架构
	SystemOs     string  `json:"system_os"`      //操作系统名称
	Runtime      uint64  `json:"run_time"`       //服务运行时间,纳秒
	Uptime       uint64  `json:"up_time"`        //操作系统运行时间,秒
	GoroutineNum int     `json:"goroutine_num"`  //goroutine数量
	CpuNum       int     `json:"cpu_num"`        //cpu核数
	CpuUser      float64 `json:"cpu_user"`       //cpu用户态比率
	CpuFree      float64 `json:"cpu_free"`       //cpu空闲比率
	DiskUsed     uint64  `json:"disk_used"`      //已用磁盘空间,字节数
	DiskFree     uint64  `json:"disk_free"`      //可用磁盘空间,字节数
	DiskTotal    uint64  `json:"disk_total"`     //总磁盘空间,字节数
	MemUsed      uint64  `json:"mem_used"`       //已用内存,字节数
	MemSys       uint64  `json:"mem_sys"`        //系统内存占用量,字节数
	MemFree      uint64  `json:"mem_free"`       //剩余内存,字节数
	MemTotal     uint64  `json:"mem_total"`      //总内存,字节数
	AllocGolang  uint64  `json:"alloc_golang"`   //golang内存使用量,字节数
	AllocTotal   uint64  `json:"alloc_total"`    //总分配的内存,字节数
	Lookups      uint64  `json:"lookups"`        //指针查找次数
	Mallocs      uint64  `json:"mallocs"`        //内存分配次数
	Frees        uint64  `json:"frees"`          //内存释放次数
	LastGCTime   uint64  `json:"last_gc_time"`   //上次GC时间,纳秒
	NextGC       uint64  `json:"next_gc"`        //下次GC内存回收量,字节数
	PauseTotalNs uint64  `json:"pause_total_ns"` //GC暂停时间总量,纳秒
	PauseNs      uint64  `json:"pause_ns"`       //上次GC暂停时间,纳秒
}

SystemInfo 系统信息

func GetSystemInfo

func GetSystemInfo() *SystemInfo

GetSystemInfo 获取系统运行信息.

type Watcher

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

Watcher is used for record code excution time

func (*Watcher) GetElapsedTime

func (w *Watcher) GetElapsedTime() time.Duration

GetElapsedTime get excute elapsed time.

func (*Watcher) Reset

func (w *Watcher) Reset()

Reset the watch timer.

func (*Watcher) Start

func (w *Watcher) Start()

Start the watch timer.

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop the watch timer.

Jump to

Keyboard shortcuts

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