github.com/PandaGoAdmin/utils@v0.0.0-20211208134815-d5461603a00f/docs/v0.0.2.md (about)

     1  # kgo
     2  
     3      import "github.com/PandaGoAdmin/utils"
     4  
     5  
     6  ## Usage
     7  
     8  ```go
     9  const (
    10  	// Version 版本号
    11  	Version = "0.0.2"
    12  
    13  	//UINT_MAX 无符号整型uint最大值
    14  	UINT_MAX = ^uint(0)
    15  	//UINT_MIN 无符号整型uint最小值
    16  	UINT_MIN uint = 0
    17  
    18  	//UINT64_MAX 无符号整型uint64最大值, 18446744073709551615
    19  	UINT64_MAX = ^uint64(0)
    20  	//UINT64_MIN 无符号整型uint64最小值
    21  	UINT64_MIN uint64 = 0
    22  
    23  	//INT_MAX 有符号整型int最大值
    24  	INT_MAX = int(^uint(0) >> 1)
    25  	//INT_MIN 有符号整型int最小值
    26  	INT_MIN = ^INT_MAX
    27  
    28  	//INT64_MAX 有符号整型int64最大值, 9223372036854775807
    29  	INT64_MAX = int64(^uint(0) >> 1)
    30  	//INT64_MIN 有符号整型int64最小值, -9223372036854775808
    31  	INT64_MIN = ^INT64_MAX
    32  
    33  	// FILE_COVER_ALLOW 文件覆盖,允许
    34  	FILE_COVER_ALLOW LkkFileCover = 1
    35  	// FILE_COVER_IGNORE 文件覆盖,忽略
    36  	FILE_COVER_IGNORE LkkFileCover = 0
    37  	// FILE_COVER_DENY 文件覆盖,禁止
    38  	FILE_COVER_DENY LkkFileCover = -1
    39  
    40  	// FILE_TREE_ALL 文件树,查找所有(包括目录和文件)
    41  	FILE_TREE_ALL LkkFileTree = 3
    42  	// FILE_TREE_DIR 文件树,仅查找目录
    43  	FILE_TREE_DIR LkkFileTree = 2
    44  	// FILE_TREE_FILE 文件树,仅查找文件
    45  	FILE_TREE_FILE LkkFileTree = 1
    46  
    47  	// RAND_STRING_ALPHA 随机字符串类型,字母
    48  	RAND_STRING_ALPHA LkkRandString = 0
    49  	// RAND_STRING_NUMERIC 随机字符串类型,数值
    50  	RAND_STRING_NUMERIC LkkRandString = 1
    51  	// RAND_STRING_ALPHANUM 随机字符串类型,字母+数值
    52  	RAND_STRING_ALPHANUM LkkRandString = 2
    53  	// RAND_STRING_SPECIAL 随机字符串类型,字母+数值+特殊字符
    54  	RAND_STRING_SPECIAL LkkRandString = 3
    55  	// RAND_STRING_CHINESE 随机字符串类型,仅中文
    56  	RAND_STRING_CHINESE LkkRandString = 4
    57  
    58  	// CASE_NONE 忽略大小写
    59  	CASE_NONE LkkCaseSwitch = 0
    60  	// CASE_LOWER 检查小写
    61  	CASE_LOWER LkkCaseSwitch = 1
    62  	// CASE_UPPER 检查大写
    63  	CASE_UPPER LkkCaseSwitch = 2
    64  
    65  	// PAD_LEFT 左侧填充
    66  	PAD_LEFT LkkPadType = 0
    67  	// PAD_RIGHT 右侧填充
    68  	PAD_RIGHT LkkPadType = 1
    69  	// PAD_BOTH 两侧填充
    70  	PAD_BOTH LkkPadType = 2
    71  
    72  	//默认浮点数精确小数位数
    73  	FLOAT_DECIMAL = 10
    74  
    75  	//检查连接超时的时间
    76  	CHECK_CONNECT_TIMEOUT = time.Second * 5
    77  
    78  	// 正则模式-全中文
    79  	PATTERN_CHINESE_ALL = "^[\u4e00-\u9fa5]+$"
    80  
    81  	// 正则模式-中文名称
    82  	PATTERN_CHINESE_NAME = "^[\u4e00-\u9fa5][.•·\u4e00-\u9fa5]{0,30}[\u4e00-\u9fa5]$"
    83  
    84  	// 正则模式-多字节字符
    85  	PATTERN_MULTIBYTE = "[^\x00-\x7F]"
    86  
    87  	// 正则模式-ASCII字符
    88  	PATTERN_ASCII = "^[\x00-\x7F]+$"
    89  
    90  	// 正则模式-全角字符
    91  	PATTERN_FULLWIDTH = "[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]"
    92  
    93  	// 正则模式-半角字符
    94  	PATTERN_HALFWIDTH = "[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]"
    95  
    96  	// 正则模式-浮点数
    97  	PATTERN_FLOAT = `^(-?\d+)(\.\d+)?`
    98  
    99  	// 正则模式-邮箱
   100  	PATTERN_EMAIL = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
   101  
   102  	// 正则模式-大陆手机号
   103  	PATTERN_MOBILECN = `^1[3-9]\d{9}$`
   104  
   105  	// 正则模式-固定电话
   106  	PATTERN_TEL_FIX = `^(010|02\d{1}|0[3-9]\d{2})-\d{7,9}(-\d+)?$`
   107  
   108  	// 正则模式-400或800
   109  	PATTERN_TEL_4800 = `^[48]00\d?(-?\d{3,4}){2}$`
   110  
   111  	// 正则模式-座机号(固定电话或400或800)
   112  	PATTERN_TELEPHONE = `(` + PATTERN_TEL_FIX + `)|(` + PATTERN_TEL_4800 + `)`
   113  
   114  	// 正则模式-电话(手机或固话)
   115  	PATTERN_PHONE = `(` + PATTERN_MOBILECN + `)|(` + PATTERN_TEL_FIX + `)`
   116  
   117  	// 正则模式-日期时间
   118  	PATTERN_DATETIME = `^[0-9]{4}(|\-[0-9]{2}(|\-[0-9]{2}(|\s+[0-9]{2}(|:[0-9]{2}(|:[0-9]{2})))))$`
   119  
   120  	// 正则模式-身份证号码,18位或15位
   121  	PATTERN_CREDIT_NO = `(^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$)`
   122  
   123  	// 正则模式-小写英文
   124  	PATTERN_ALPHA_LOWER = `^[a-z]+$`
   125  
   126  	// 正则模式-大写英文
   127  	PATTERN_ALPHA_UPPER = `^[A-Z]+$`
   128  
   129  	// 正则模式-字母和数字
   130  	PATTERN_ALPHA_NUMERIC = `^[a-zA-Z0-9]+$`
   131  
   132  	// 正则模式-十六进制颜色
   133  	PATTERN_HEXCOLOR = `^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$`
   134  
   135  	// 正则模式-RGB颜色
   136  	PATTERN_RGBCOLOR = "^rgb\\(\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*\\)$"
   137  
   138  	// 正则模式-全空白字符
   139  	PATTERN_WHITESPACE_ALL = "^[[:space:]]+$"
   140  
   141  	// 正则模式-带空白字符
   142  	PATTERN_WHITESPACE_HAS = ".*[[:space:]]"
   143  
   144  	// 正则模式-连续空白符
   145  	PATTERN_WHITESPACE_DUPLICATE = `[[:space:]]{2,}|[\s\p{Zs}]{2,}`
   146  
   147  	// 正则模式-base64字符串
   148  	PATTERN_BASE64 = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$"
   149  
   150  	// 正则模式-base64编码图片
   151  	PATTERN_BASE64_IMAGE = `^data:\s*(image|img)\/(\w+);base64`
   152  
   153  	// 正则模式-html标签
   154  	PATTERN_HTML_TAGS = `<(.|\n)*?>`
   155  
   156  	// 正则模式-DNS名称
   157  	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})*[\._]?$`
   158  
   159  	// 正则模式-MD5
   160  	PATTERN_MD5 = `^(?i)([0-9a-h]{32})$`
   161  
   162  	// 正则模式-SHA1
   163  	PATTERN_SHA1 = `^(?i)([0-9a-h]{40})$`
   164  
   165  	// 正则模式-SHA256
   166  	PATTERN_SHA256 = `^(?i)([0-9a-h]{64})$`
   167  
   168  	// 正则模式-SHA512
   169  	PATTERN_SHA512 = `^(?i)([0-9a-h]{128})$`
   170  )
   171  ```
   172  
   173  ```go
   174  var (
   175  	// Kuptime 当前服务启动时间
   176  	Kuptime = time.Now()
   177  
   178  	// KFile utilities
   179  	KFile LkkFile
   180  
   181  	// KStr utilities
   182  	KStr LkkString
   183  
   184  	// KNum utilities
   185  	KNum LkkNumber
   186  
   187  	// KArr utilities
   188  	KArr LkkArray
   189  
   190  	// KTime utilities
   191  	KTime LkkTime
   192  
   193  	// KConv utilities
   194  	KConv LkkConvert
   195  
   196  	// KOS utilities
   197  	KOS LkkOS
   198  
   199  	// KEncr utilities
   200  	KEncr LkkEncrypt
   201  
   202  	// KDbug utilities
   203  	KDbug LkkDebug
   204  
   205  	// KPrivCidrs 私有网段的CIDR数组
   206  	KPrivCidrs []*net.IPNet
   207  
   208  	// KDelimiter 自定义分隔符
   209  	KDelimiter = "$@#KGO#@$"
   210  
   211  	// 身份证区域
   212  	CreditArea = map[string]string{"11": "北京", "12": "天津", "13": "河北", "14": "山西", "15": "内蒙古", "21": "辽宁", "22": "吉林", "23": "黑龙江", " 31": "上海", "32": "江苏", "33": "浙江", "34": "安徽", "35": "福建", "36": "江西", "37": "山东", "41": "河南", "42": "湖北", "43": "湖南", "44": "广东", "45": "广西", "46": "海南", "50": "重庆", "51": "四川", "52": "贵州", "53": "云南", "54": "西藏", "61": "陕西", "62": "甘肃", "63": "青海", "64": "宁夏", "65": "新疆", "71": "台湾", "81": "香港", "82": "澳门", "91": "国外"}
   213  
   214  	// html抽取文本要排除的标签
   215  	TextHtmlExcludeTags = []string{"head", "title", "img", "form", "textarea", "input", "select", "button", "iframe", "script", "style", "option"}
   216  
   217  	// 已编译的正则
   218  	RegFormatDir             = regexp.MustCompile(`[\/]{2,}`) //连续的"//"或"\\"或"\/"或"/\"
   219  	RegChineseAll            = regexp.MustCompile(PATTERN_CHINESE_ALL)
   220  	RegChineseName           = regexp.MustCompile(PATTERN_CHINESE_NAME)
   221  	RegMultiByte             = regexp.MustCompile(PATTERN_MULTIBYTE)
   222  	RegFullWidth             = regexp.MustCompile(PATTERN_FULLWIDTH)
   223  	RegHalfWidth             = regexp.MustCompile(PATTERN_HALFWIDTH)
   224  	RegFloat                 = regexp.MustCompile(PATTERN_FLOAT)
   225  	RegEmail                 = regexp.MustCompile(PATTERN_EMAIL)
   226  	RegMobilecn              = regexp.MustCompile(PATTERN_MOBILECN)
   227  	RegTelephone             = regexp.MustCompile(PATTERN_TELEPHONE)
   228  	RegPhone                 = regexp.MustCompile(PATTERN_PHONE)
   229  	RegDatetime              = regexp.MustCompile(PATTERN_DATETIME)
   230  	RegCreditno              = regexp.MustCompile(PATTERN_CREDIT_NO)
   231  	RegAlphaLower            = regexp.MustCompile(PATTERN_ALPHA_LOWER)
   232  	RegAlphaUpper            = regexp.MustCompile(PATTERN_ALPHA_UPPER)
   233  	RegAlphaNumeric          = regexp.MustCompile(PATTERN_ALPHA_NUMERIC)
   234  	RegHexcolor              = regexp.MustCompile(PATTERN_HEXCOLOR)
   235  	RegRgbcolor              = regexp.MustCompile(PATTERN_RGBCOLOR)
   236  	RegWhitespace            = regexp.MustCompile(`\s`)
   237  	RegWhitespaceAll         = regexp.MustCompile(PATTERN_WHITESPACE_ALL)
   238  	RegWhitespaceHas         = regexp.MustCompile(PATTERN_WHITESPACE_HAS)
   239  	RegWhitespaceDuplicate   = regexp.MustCompile(PATTERN_WHITESPACE_DUPLICATE)
   240  	RegBase64                = regexp.MustCompile(PATTERN_BASE64)
   241  	RegBase64Image           = regexp.MustCompile(PATTERN_BASE64_IMAGE)
   242  	RegHtmlTag               = regexp.MustCompile(PATTERN_HTML_TAGS)
   243  	RegDNSname               = regexp.MustCompile(PATTERN_DNSNAME)
   244  	RegUrlBackslashDuplicate = regexp.MustCompile(`([^:])[\/]{2,}`) //url中连续的"//"或"\\"或"\/"或"/\"
   245  	RegMd5                   = regexp.MustCompile(PATTERN_MD5)
   246  	RegSha1                  = regexp.MustCompile(PATTERN_SHA1)
   247  	RegSha256                = regexp.MustCompile(PATTERN_SHA256)
   248  	RegSha512                = regexp.MustCompile(PATTERN_SHA512)
   249  )
   250  ```
   251  
   252  #### func  CallFunc
   253  
   254  ```go
   255  func CallFunc(f interface{}, args ...interface{}) (results []interface{}, err error)
   256  ```
   257  CallFunc 动态调用函数.
   258  
   259  #### func  ValidFunc
   260  
   261  ```go
   262  func ValidFunc(f interface{}, args ...interface{}) (vf reflect.Value, vargs []reflect.Value, err error)
   263  ```
   264  ValidFunc 检查是否函数,并且参数个数、类型是否正确. 返回有效的函数、有效的参数.
   265  
   266  #### type CallBack
   267  
   268  ```go
   269  type CallBack func()
   270  ```
   271  
   272  CallBack 回调执行函数,无参数且无返回值
   273  
   274  #### type FileFilter
   275  
   276  ```go
   277  type FileFilter func(string) bool
   278  ```
   279  
   280  FileFilter 文件过滤函数
   281  
   282  #### type LkkArray
   283  
   284  ```go
   285  type LkkArray byte
   286  ```
   287  
   288  LkkArray is the receiver of array utilities
   289  
   290  #### func (*LkkArray) ArrayChunk
   291  
   292  ```go
   293  func (ka *LkkArray) ArrayChunk(arr interface{}, size int) [][]interface{}
   294  ```
   295  ArrayChunk 将一个数组分割成多个,size为每个子数组的长度.
   296  
   297  #### func (*LkkArray) ArrayColumn
   298  
   299  ```go
   300  func (ka *LkkArray) ArrayColumn(arr interface{}, columnKey string) []interface{}
   301  ```
   302  ArrayColumn 返回数组中指定的一列. arr的元素必须是字典;该方法效率低,因为嵌套了两层反射和遍历.
   303  
   304  #### func (*LkkArray) ArrayDiff
   305  
   306  ```go
   307  func (ka *LkkArray) ArrayDiff(arr1, arr2 interface{}) []interface{}
   308  ```
   309  ArrayDiff 计算数组(数组/切片/字典)的差集,返回在 arr1 中但是不在 arr2 里,且非空元素(nil,'')的值.
   310  
   311  #### func (*LkkArray) ArrayFill
   312  
   313  ```go
   314  func (ka *LkkArray) ArrayFill(value interface{}, num int) []interface{}
   315  ```
   316  ArrayFill 用给定的值value填充数组,num为插入元素的数量.
   317  
   318  #### func (*LkkArray) ArrayFlip
   319  
   320  ```go
   321  func (ka *LkkArray) ArrayFlip(arr interface{}) map[interface{}]interface{}
   322  ```
   323  ArrayFlip 交换数组中的键和值.
   324  
   325  #### func (*LkkArray) ArrayKeyExists
   326  
   327  ```go
   328  func (ka *LkkArray) ArrayKeyExists(key interface{}, arr interface{}) bool
   329  ```
   330  ArrayKeyExists 检查数组里是否有指定的键名或索引.
   331  
   332  #### func (*LkkArray) ArrayKeys
   333  
   334  ```go
   335  func (ka *LkkArray) ArrayKeys(arr interface{}) []interface{}
   336  ```
   337  ArrayKeys 返回数组中所有的键名.
   338  
   339  #### func (*LkkArray) ArrayPad
   340  
   341  ```go
   342  func (ka *LkkArray) ArrayPad(arr interface{}, size int, item interface{}) []interface{}
   343  ```
   344  ArrayPad 以指定长度将一个值item填充进数组. 若 size 为正,则填补到数组的右侧,如果为负则从左侧开始填补; 若 size 的绝对值小于或等于
   345  arr 数组的长度则没有任何填补.
   346  
   347  #### func (*LkkArray) ArrayPop
   348  
   349  ```go
   350  func (ka *LkkArray) ArrayPop(s *[]interface{}) interface{}
   351  ```
   352  ArrayPop 弹出数组最后一个元素(出栈),并返回该元素.
   353  
   354  #### func (*LkkArray) ArrayPush
   355  
   356  ```go
   357  func (ka *LkkArray) ArrayPush(s *[]interface{}, elements ...interface{}) int
   358  ```
   359  ArrayPush 将一个或多个元素压入数组的末尾(入栈),返回处理之后数组的元素个数.
   360  
   361  #### func (*LkkArray) ArrayRand
   362  
   363  ```go
   364  func (ka *LkkArray) ArrayRand(arr interface{}, num int) []interface{}
   365  ```
   366  ArrayRand 从数组中随机取出num个单元.
   367  
   368  #### func (*LkkArray) ArrayReverse
   369  
   370  ```go
   371  func (ka *LkkArray) ArrayReverse(arr interface{}) []interface{}
   372  ```
   373  ArrayReverse 返回单元顺序相反的数组(仅限数组和切片).
   374  
   375  #### func (*LkkArray) ArraySearchItem
   376  
   377  ```go
   378  func (ka *LkkArray) ArraySearchItem(arr interface{}, condition map[string]interface{}) (res interface{})
   379  ```
   380  ArraySearchItem 从数组中搜索对应元素(单个). arr为要查找的数组,condition为条件字典.
   381  
   382  #### func (*LkkArray) ArraySearchMutil
   383  
   384  ```go
   385  func (ka *LkkArray) ArraySearchMutil(arr interface{}, condition map[string]interface{}) (res []interface{})
   386  ```
   387  ArraySearchMutil 从数组中搜索对应元素(多个). arr为要查找的数组,condition为条件字典.
   388  
   389  #### func (*LkkArray) ArrayShift
   390  
   391  ```go
   392  func (ka *LkkArray) ArrayShift(s *[]interface{}) interface{}
   393  ```
   394  ArrayShift 将数组开头的元素移出数组,并返回该元素.
   395  
   396  #### func (*LkkArray) ArraySlice
   397  
   398  ```go
   399  func (ka *LkkArray) ArraySlice(arr interface{}, offset, size int) []interface{}
   400  ```
   401  ArraySlice 返回根据 offset 和 size 参数所指定的 arr 数组中的一段切片.
   402  
   403  #### func (*LkkArray) ArrayUnique
   404  
   405  ```go
   406  func (ka *LkkArray) ArrayUnique(arr interface{}) []interface{}
   407  ```
   408  ArrayUnique 移除数组中重复的值.
   409  
   410  #### func (*LkkArray) ArrayUnshift
   411  
   412  ```go
   413  func (ka *LkkArray) ArrayUnshift(s *[]interface{}, elements ...interface{}) int
   414  ```
   415  ArrayUnshift 在数组开头插入一个或多个元素,返回处理之后数组的元素个数.
   416  
   417  #### func (*LkkArray) ArrayValues
   418  
   419  ```go
   420  func (ka *LkkArray) ArrayValues(arr interface{}, filterNil bool) []interface{}
   421  ```
   422  ArrayValues 返回数组(切片/字典)中所有的值. filterNil是否过滤空元素(nil,''),true时排除空元素,false时保留空元素.
   423  
   424  #### func (*LkkArray) Implode
   425  
   426  ```go
   427  func (ka *LkkArray) Implode(delimiter string, arr interface{}) string
   428  ```
   429  Implode 用delimiter将数组(数组/切片/字典)的值连接为一个字符串.
   430  
   431  #### func (*LkkArray) InArray
   432  
   433  ```go
   434  func (ka *LkkArray) InArray(needle interface{}, haystack interface{}) bool
   435  ```
   436  InArray 元素是否在数组(切片/字典)内.
   437  
   438  #### func (*LkkArray) IsArrayOrSlice
   439  
   440  ```go
   441  func (ka *LkkArray) IsArrayOrSlice(val interface{}, chkType uint8) int
   442  ```
   443  IsArrayOrSlice 检查变量是否数组或切片. chkType检查类型,枚举值有(1仅数组,2仅切片,3数组或切片);结果为-1表示非,>=0表示是
   444  
   445  #### func (*LkkArray) IsMap
   446  
   447  ```go
   448  func (ka *LkkArray) IsMap(val interface{}) bool
   449  ```
   450  IsMap 检查变量是否字典.
   451  
   452  #### func (*LkkArray) JoinInts
   453  
   454  ```go
   455  func (ka *LkkArray) JoinInts(ints []int, delimiter string) (res string)
   456  ```
   457  JoinInts 使用分隔符delimiter连接整数数组.
   458  
   459  #### func (*LkkArray) JoinStrings
   460  
   461  ```go
   462  func (ka *LkkArray) JoinStrings(strs []string, delimiter string) (res string)
   463  ```
   464  JoinStrings 使用分隔符delimiter连接字符串数组.效率比Implode高.
   465  
   466  #### func (*LkkArray) MergeMap
   467  
   468  ```go
   469  func (ka *LkkArray) MergeMap(key2Str bool, ss ...interface{}) map[interface{}]interface{}
   470  ```
   471  MergeMap 合并字典. 相同的键名时,后面的值将覆盖前一个值;key2Str是否将键转换为字符串;ss是元素为字典的数组.
   472  
   473  #### func (*LkkArray) MergeSlice
   474  
   475  ```go
   476  func (ka *LkkArray) MergeSlice(filterNil bool, ss ...interface{}) []interface{}
   477  ```
   478  MergeSlice 合并一个或多个数组/切片.
   479  filterNil是否过滤空元素(nil,''),true时排除空元素,false时保留空元素;ss是元素为数组/切片的数组.
   480  
   481  #### func (*LkkArray) Unique64Ints
   482  
   483  ```go
   484  func (ka *LkkArray) Unique64Ints(ints []int64) (res []int64)
   485  ```
   486  Unique64Ints 移除64位整数数组中的重复值.
   487  
   488  #### func (*LkkArray) UniqueInts
   489  
   490  ```go
   491  func (ka *LkkArray) UniqueInts(ints []int) (res []int)
   492  ```
   493  UniqueInts 移除整数数组中的重复值.
   494  
   495  #### func (*LkkArray) UniqueStrings
   496  
   497  ```go
   498  func (ka *LkkArray) UniqueStrings(strs []string) (res []string)
   499  ```
   500  UniqueStrings 移除字符串数组中的重复值.
   501  
   502  #### type LkkCaseSwitch
   503  
   504  ```go
   505  type LkkCaseSwitch uint8
   506  ```
   507  
   508  LkkCaseSwitch 枚举类型,大小写开关
   509  
   510  #### type LkkConvert
   511  
   512  ```go
   513  type LkkConvert byte
   514  ```
   515  
   516  LkkConvert is the receiver of convert utilities
   517  
   518  #### func (*LkkConvert) BaseConvert
   519  
   520  ```go
   521  func (kc *LkkConvert) BaseConvert(number string, frombase, tobase int) (string, error)
   522  ```
   523  BaseConvert 进制转换,在任意进制之间转换数字.
   524  
   525  #### func (*LkkConvert) Bin2Dec
   526  
   527  ```go
   528  func (kc *LkkConvert) Bin2Dec(str string) (int64, error)
   529  ```
   530  Bin2Dec 将二进制转换为十进制.
   531  
   532  #### func (*LkkConvert) Bin2Hex
   533  
   534  ```go
   535  func (kc *LkkConvert) Bin2Hex(str string) (string, error)
   536  ```
   537  Bin2Hex 将二进制字符串转换为十六进制字符串.
   538  
   539  #### func (*LkkConvert) Bool2Int
   540  
   541  ```go
   542  func (kc *LkkConvert) Bool2Int(val bool) int
   543  ```
   544  Bool2Int 将布尔值转换为整型.
   545  
   546  #### func (*LkkConvert) Bool2Str
   547  
   548  ```go
   549  func (kc *LkkConvert) Bool2Str(val bool) string
   550  ```
   551  Bool2Str 将布尔值转换为字符串.
   552  
   553  #### func (*LkkConvert) Byte2Float64
   554  
   555  ```go
   556  func (kc *LkkConvert) Byte2Float64(bytes []byte) float64
   557  ```
   558  Byte2Float64 字节切片转64位浮点数.
   559  
   560  #### func (*LkkConvert) Byte2Hex
   561  
   562  ```go
   563  func (kc *LkkConvert) Byte2Hex(val []byte) string
   564  ```
   565  Byte2Hex 字节切片转16进制字符串.
   566  
   567  #### func (*LkkConvert) Byte2Int64
   568  
   569  ```go
   570  func (kc *LkkConvert) Byte2Int64(val []byte) int64
   571  ```
   572  Byte2Int64 字节切片转64位整型.
   573  
   574  #### func (*LkkConvert) Bytes2Str
   575  
   576  ```go
   577  func (kc *LkkConvert) Bytes2Str(val []byte) string
   578  ```
   579  Bytes2Str 将字节切片转换为字符串. 零拷贝,不安全.效率是string([]byte{})的百倍以上,且转换量越大效率优势越明显.
   580  
   581  #### func (*LkkConvert) Dec2Bin
   582  
   583  ```go
   584  func (kc *LkkConvert) Dec2Bin(number int64) string
   585  ```
   586  Dec2Bin 将十进制转换为二进制.
   587  
   588  #### func (*LkkConvert) Dec2Hex
   589  
   590  ```go
   591  func (kc *LkkConvert) Dec2Hex(number int64) string
   592  ```
   593  Dec2Hex 将十进制转换为十六进制.
   594  
   595  #### func (*LkkConvert) Dec2Oct
   596  
   597  ```go
   598  func (kc *LkkConvert) Dec2Oct(number int64) string
   599  ```
   600  Dec2Oct 将十进制转换为八进制.
   601  
   602  #### func (*LkkConvert) Float2Str
   603  
   604  ```go
   605  func (kc *LkkConvert) Float2Str(val interface{}, decimal int) string
   606  ```
   607  Float2Str 将浮点数转换为字符串,decimal为小数位数.
   608  
   609  #### func (*LkkConvert) Float64ToByte
   610  
   611  ```go
   612  func (kc *LkkConvert) Float64ToByte(val float64) []byte
   613  ```
   614  Float64ToByte 64位浮点数转字节切片.
   615  
   616  #### func (*LkkConvert) GetPointerAddrInt
   617  
   618  ```go
   619  func (kc *LkkConvert) GetPointerAddrInt(variable interface{}) int64
   620  ```
   621  GetPointerAddrInt 获取变量指针地址整型值.variable为变量.
   622  
   623  #### func (*LkkConvert) Gettype
   624  
   625  ```go
   626  func (kc *LkkConvert) Gettype(v interface{}) string
   627  ```
   628  Gettype 获取变量类型.
   629  
   630  #### func (*LkkConvert) Hex2Bin
   631  
   632  ```go
   633  func (kc *LkkConvert) Hex2Bin(data string) (string, error)
   634  ```
   635  Hex2Bin 将十六进制字符串转换为二进制字符串.
   636  
   637  #### func (*LkkConvert) Hex2Byte
   638  
   639  ```go
   640  func (kc *LkkConvert) Hex2Byte(str string) []byte
   641  ```
   642  Hex2Byte 16进制字符串转字节切片.
   643  
   644  #### func (*LkkConvert) Hex2Dec
   645  
   646  ```go
   647  func (kc *LkkConvert) Hex2Dec(str string) (int64, error)
   648  ```
   649  Hex2Dec 将十六进制转换为十进制.
   650  
   651  #### func (*LkkConvert) Int2Str
   652  
   653  ```go
   654  func (kc *LkkConvert) Int2Str(val interface{}) string
   655  ```
   656  Int2Str 将整数转换为字符串.
   657  
   658  #### func (*LkkConvert) Int64ToByte
   659  
   660  ```go
   661  func (kc *LkkConvert) Int64ToByte(val int64) []byte
   662  ```
   663  Int64ToByte 64位整型转字节切片.
   664  
   665  #### func (*LkkConvert) Ip2Long
   666  
   667  ```go
   668  func (kc *LkkConvert) Ip2Long(ipAddress string) uint32
   669  ```
   670  Ip2Long 将 IPV4 的字符串互联网协议转换成长整型数字.
   671  
   672  #### func (*LkkConvert) IsBinary
   673  
   674  ```go
   675  func (kc *LkkConvert) IsBinary(s string) bool
   676  ```
   677  IsBinary 字符串是否二进制.
   678  
   679  #### func (*LkkConvert) IsBool
   680  
   681  ```go
   682  func (kc *LkkConvert) IsBool(val interface{}) bool
   683  ```
   684  IsBool 是否布尔值.
   685  
   686  #### func (*LkkConvert) IsByte
   687  
   688  ```go
   689  func (kc *LkkConvert) IsByte(val interface{}) bool
   690  ```
   691  IsByte 变量是否字节切片.
   692  
   693  #### func (*LkkConvert) IsEmpty
   694  
   695  ```go
   696  func (kc *LkkConvert) IsEmpty(val interface{}) bool
   697  ```
   698  IsEmpty 检查变量是否为空.
   699  
   700  #### func (*LkkConvert) IsFloat
   701  
   702  ```go
   703  func (kc *LkkConvert) IsFloat(val interface{}) bool
   704  ```
   705  IsFloat 变量是否浮点数值.
   706  
   707  #### func (*LkkConvert) IsHex
   708  
   709  ```go
   710  func (kc *LkkConvert) IsHex(str string) bool
   711  ```
   712  IsHex 是否十六进制字符串.
   713  
   714  #### func (*LkkConvert) IsInt
   715  
   716  ```go
   717  func (kc *LkkConvert) IsInt(val interface{}) bool
   718  ```
   719  IsInt 变量是否整型数值.
   720  
   721  #### func (*LkkConvert) IsInterface
   722  
   723  ```go
   724  func (kc *LkkConvert) IsInterface(val interface{}) bool
   725  ```
   726  IsInterface 变量是否接口.
   727  
   728  #### func (*LkkConvert) IsNil
   729  
   730  ```go
   731  func (kc *LkkConvert) IsNil(val interface{}) bool
   732  ```
   733  IsNil 检查变量是否空值.
   734  
   735  #### func (*LkkConvert) IsNumeric
   736  
   737  ```go
   738  func (kc *LkkConvert) IsNumeric(val interface{}) bool
   739  ```
   740  IsNumeric 变量是否数值(不包含复数和科学计数法).
   741  
   742  #### func (*LkkConvert) IsString
   743  
   744  ```go
   745  func (kc *LkkConvert) IsString(val interface{}) bool
   746  ```
   747  IsString 变量是否字符串.
   748  
   749  #### func (*LkkConvert) IsStruct
   750  
   751  ```go
   752  func (kc *LkkConvert) IsStruct(val interface{}) bool
   753  ```
   754  IsStruct 变量是否结构体.
   755  
   756  #### func (*LkkConvert) Long2Ip
   757  
   758  ```go
   759  func (kc *LkkConvert) Long2Ip(properAddress uint32) string
   760  ```
   761  Long2Ip 将长整型转化为字符串形式带点的互联网标准格式地址(IPV4).
   762  
   763  #### func (*LkkConvert) Oct2Dec
   764  
   765  ```go
   766  func (kc *LkkConvert) Oct2Dec(str string) (int64, error)
   767  ```
   768  Oct2Dec 将八进制转换为十进制.
   769  
   770  #### func (*LkkConvert) Str2Bool
   771  
   772  ```go
   773  func (kc *LkkConvert) Str2Bool(val string) (res bool)
   774  ```
   775  Str2Bool 将字符串转换为布尔值. 1, t, T, TRUE, true, True 等字符串为真. 0, f, F, FALSE, false,
   776  False 等字符串为假.
   777  
   778  #### func (*LkkConvert) Str2Bytes
   779  
   780  ```go
   781  func (kc *LkkConvert) Str2Bytes(val string) []byte
   782  ```
   783  Str2Bytes 将字符串转换为字节切片. 该方法零拷贝,但不安全.它直接转换底层指针,两者指向的相同的内存,改一个另外一个也会变.
   784  仅当临时需将长字符串转换且不长时间保存时可以使用. 转换之后若没做其他操作直接改变里面的字符,则程序会崩溃. 如 b:=String2bytes("xxx");
   785  b[1]='d'; 程序将panic.
   786  
   787  #### func (*LkkConvert) Str2Float32
   788  
   789  ```go
   790  func (kc *LkkConvert) Str2Float32(val string) float32
   791  ```
   792  Str2Float32 将字符串转换为float32.
   793  
   794  #### func (*LkkConvert) Str2Float64
   795  
   796  ```go
   797  func (kc *LkkConvert) Str2Float64(val string) (res float64)
   798  ```
   799  Str2Float64 将字符串转换为float64.其中"true", "TRUE", "True"为1.0 .
   800  
   801  #### func (*LkkConvert) Str2FloatStrict
   802  
   803  ```go
   804  func (kc *LkkConvert) Str2FloatStrict(val string, bitSize int, strict bool) float64
   805  ```
   806  Str2FloatStrict 严格将字符串转换为浮点型. bitSize为类型位数,strict为是否严格检查.
   807  
   808  #### func (*LkkConvert) Str2Int
   809  
   810  ```go
   811  func (kc *LkkConvert) Str2Int(val string) (res int)
   812  ```
   813  Str2Int 将字符串转换为int.其中"true", "TRUE", "True"为1.
   814  
   815  #### func (*LkkConvert) Str2Int16
   816  
   817  ```go
   818  func (kc *LkkConvert) Str2Int16(val string) int16
   819  ```
   820  Str2Int16 将字符串转换为int16.
   821  
   822  #### func (*LkkConvert) Str2Int32
   823  
   824  ```go
   825  func (kc *LkkConvert) Str2Int32(val string) int32
   826  ```
   827  Str2Int32 将字符串转换为int32.
   828  
   829  #### func (*LkkConvert) Str2Int64
   830  
   831  ```go
   832  func (kc *LkkConvert) Str2Int64(val string) int64
   833  ```
   834  Str2Int64 将字符串转换为int64.
   835  
   836  #### func (*LkkConvert) Str2Int8
   837  
   838  ```go
   839  func (kc *LkkConvert) Str2Int8(val string) int8
   840  ```
   841  Str2Int8 将字符串转换为int8.
   842  
   843  #### func (*LkkConvert) Str2IntStrict
   844  
   845  ```go
   846  func (kc *LkkConvert) Str2IntStrict(val string, bitSize int, strict bool) int64
   847  ```
   848  Str2IntStrict 严格将字符串转换为有符号整型. bitSize为类型位数,strict为是否严格检查.
   849  
   850  #### func (*LkkConvert) Str2Uint
   851  
   852  ```go
   853  func (kc *LkkConvert) Str2Uint(val string) uint
   854  ```
   855  Str2Uint 将字符串转换为uint.
   856  
   857  #### func (*LkkConvert) Str2Uint16
   858  
   859  ```go
   860  func (kc *LkkConvert) Str2Uint16(val string) uint16
   861  ```
   862  Str2Uint16 将字符串转换为uint16.
   863  
   864  #### func (*LkkConvert) Str2Uint32
   865  
   866  ```go
   867  func (kc *LkkConvert) Str2Uint32(val string) uint32
   868  ```
   869  Str2Uint32 将字符串转换为uint32.
   870  
   871  #### func (*LkkConvert) Str2Uint64
   872  
   873  ```go
   874  func (kc *LkkConvert) Str2Uint64(val string) uint64
   875  ```
   876  Str2Uint64 将字符串转换为uint64.
   877  
   878  #### func (*LkkConvert) Str2Uint8
   879  
   880  ```go
   881  func (kc *LkkConvert) Str2Uint8(val string) uint8
   882  ```
   883  Str2Uint8 将字符串转换为uint8.
   884  
   885  #### func (*LkkConvert) Str2UintStrict
   886  
   887  ```go
   888  func (kc *LkkConvert) Str2UintStrict(val string, bitSize int, strict bool) uint64
   889  ```
   890  Str2UintStrict 严格将字符串转换为无符号整型,bitSize为类型位数,strict为是否严格检查
   891  
   892  #### func (*LkkConvert) ToBool
   893  
   894  ```go
   895  func (kc *LkkConvert) ToBool(val interface{}) bool
   896  ```
   897  ToBool 强制将变量转换为布尔值.
   898  
   899  #### func (*LkkConvert) ToFloat
   900  
   901  ```go
   902  func (kc *LkkConvert) ToFloat(val interface{}) (res float64)
   903  ```
   904  ToFloat 强制将变量转换为浮点型;其中true或"true"为1.0 .
   905  
   906  #### func (*LkkConvert) ToInt
   907  
   908  ```go
   909  func (kc *LkkConvert) ToInt(val interface{}) int
   910  ```
   911  ToInt 强制将变量转换为整型;其中true或"true"为1.
   912  
   913  #### func (*LkkConvert) ToStr
   914  
   915  ```go
   916  func (kc *LkkConvert) ToStr(val interface{}) string
   917  ```
   918  ToStr 强制将变量转换为字符串.
   919  
   920  #### type LkkDebug
   921  
   922  ```go
   923  type LkkDebug byte
   924  ```
   925  
   926  LkkDebug is the receiver of debug utilities
   927  
   928  #### func (*LkkDebug) CallMethod
   929  
   930  ```go
   931  func (kd *LkkDebug) CallMethod(t interface{}, method string, args ...interface{}) ([]interface{}, error)
   932  ```
   933  CallMethod 调用对象的方法. 若执行成功,则结果是该方法的返回结果; 否则返回(nil, error)
   934  
   935  #### func (*LkkDebug) DumpStacks
   936  
   937  ```go
   938  func (kd *LkkDebug) DumpStacks()
   939  ```
   940  DumpStacks 打印堆栈信息.
   941  
   942  #### func (*LkkDebug) GetFuncDir
   943  
   944  ```go
   945  func (kd *LkkDebug) GetFuncDir() string
   946  ```
   947  GetFuncDir 获取调用方法的文件目录.
   948  
   949  #### func (*LkkDebug) GetFuncFile
   950  
   951  ```go
   952  func (kd *LkkDebug) GetFuncFile() string
   953  ```
   954  GetFuncFile 获取调用方法的文件路径.
   955  
   956  #### func (*LkkDebug) GetFuncLine
   957  
   958  ```go
   959  func (kd *LkkDebug) GetFuncLine() int
   960  ```
   961  GetFuncLine 获取调用方法的行号.
   962  
   963  #### func (*LkkDebug) GetFuncName
   964  
   965  ```go
   966  func (kd *LkkDebug) GetFuncName(f interface{}, onlyFun ...bool) string
   967  ```
   968  GetFunctionName 获取调用方法的名称;f为目标方法;onlyFun为true时仅返回方法,不包括包名.
   969  
   970  #### func (*LkkDebug) GetFuncPackage
   971  
   972  ```go
   973  func (kd *LkkDebug) GetFuncPackage(funcFile ...string) string
   974  ```
   975  GetFuncPackage 获取调用方法或源文件的包名.funcFile为源文件路径.
   976  
   977  #### func (*LkkDebug) GetMethod
   978  
   979  ```go
   980  func (kd *LkkDebug) GetMethod(t interface{}, method string) interface{}
   981  ```
   982  GetMethod 获取对象中的方法. 注意:返回的该方法中的第一个参数是接收者. 所以,调用该方法时,必须将接收者作为第一个参数传递.
   983  
   984  #### func (*LkkDebug) HasMethod
   985  
   986  ```go
   987  func (kd *LkkDebug) HasMethod(t interface{}, method string) bool
   988  ```
   989  HasMethod 检查对象是否具有某方法.
   990  
   991  #### type LkkEncrypt
   992  
   993  ```go
   994  type LkkEncrypt byte
   995  ```
   996  
   997  LkkEncrypt is the receiver of encrypt utilities
   998  
   999  #### func (*LkkEncrypt) AuthCode
  1000  
  1001  ```go
  1002  func (ke *LkkEncrypt) AuthCode(str, key string, encode bool, expiry int64) (string, int64)
  1003  ```
  1004  AuthCode 授权码编码或解码;encode为true时编码,为false解码;expiry为有效期,秒;返回结果为加密/解密的字符串和有效期时间戳.
  1005  
  1006  #### func (*LkkEncrypt) Base64Decode
  1007  
  1008  ```go
  1009  func (ke *LkkEncrypt) Base64Decode(str string) ([]byte, error)
  1010  ```
  1011  Base64Decode 对使用 MIME base64 编码的数据进行解码.
  1012  
  1013  #### func (*LkkEncrypt) Base64Encode
  1014  
  1015  ```go
  1016  func (ke *LkkEncrypt) Base64Encode(str []byte) string
  1017  ```
  1018  Base64Encode 使用 MIME base64 对数据进行编码.
  1019  
  1020  #### func (*LkkEncrypt) Base64UrlDecode
  1021  
  1022  ```go
  1023  func (ke *LkkEncrypt) Base64UrlDecode(data string) ([]byte, error)
  1024  ```
  1025  Base64UrlDecode url安全的Base64Decode.
  1026  
  1027  #### func (*LkkEncrypt) Base64UrlEncode
  1028  
  1029  ```go
  1030  func (ke *LkkEncrypt) Base64UrlEncode(source []byte) string
  1031  ```
  1032  Base64UrlSafeEncode url安全的Base64Encode,没有'/'和'+'及结尾的'=' .
  1033  
  1034  #### func (*LkkEncrypt) EasyDecrypt
  1035  
  1036  ```go
  1037  func (ke *LkkEncrypt) EasyDecrypt(val, key string) string
  1038  ```
  1039  EasyDecrypt 简单解密. val为待解密的字符串,key为密钥.
  1040  
  1041  #### func (*LkkEncrypt) EasyEncrypt
  1042  
  1043  ```go
  1044  func (ke *LkkEncrypt) EasyEncrypt(data, key string) string
  1045  ```
  1046  EasyEncrypt 简单加密. data为要加密的原字符串,key为密钥.
  1047  
  1048  #### func (*LkkEncrypt) HmacShaX
  1049  
  1050  ```go
  1051  func (ke *LkkEncrypt) HmacShaX(data, secret []byte, x uint16) string
  1052  ```
  1053  HmacShaX HmacSHA-x加密,x为1/256/512 .
  1054  
  1055  #### func (*LkkEncrypt) PasswordHash
  1056  
  1057  ```go
  1058  func (ke *LkkEncrypt) PasswordHash(password []byte, costs ...int) ([]byte, error)
  1059  ```
  1060  PasswordHash 创建密码的散列值;costs为算法的cost,范围4~31,默认10,注意值越大越耗时.
  1061  
  1062  #### func (*LkkEncrypt) PasswordVerify
  1063  
  1064  ```go
  1065  func (ke *LkkEncrypt) PasswordVerify(password, hash []byte) bool
  1066  ```
  1067  PasswordVerify 验证密码是否和散列值匹配.
  1068  
  1069  #### type LkkFile
  1070  
  1071  ```go
  1072  type LkkFile byte
  1073  ```
  1074  
  1075  LkkFile is the receiver of file utilities
  1076  
  1077  #### func (*LkkFile) AbsPath
  1078  
  1079  ```go
  1080  func (kf *LkkFile) AbsPath(fpath string) string
  1081  ```
  1082  AbsPath 获取绝对路径,path可允许不存在.
  1083  
  1084  #### func (*LkkFile) Basename
  1085  
  1086  ```go
  1087  func (kf *LkkFile) Basename(fpath string) string
  1088  ```
  1089  Basename 返回路径中的文件名部分.
  1090  
  1091  #### func (*LkkFile) ChmodBatch
  1092  
  1093  ```go
  1094  func (kf *LkkFile) ChmodBatch(fpath string, filemode, dirmode os.FileMode) (res bool)
  1095  ```
  1096  ChmodBatch 批量改变路径权限模式(包括子目录和所属文件).filemode为文件权限模式,dirmode为目录权限模式.
  1097  
  1098  #### func (*LkkFile) CopyDir
  1099  
  1100  ```go
  1101  func (kf *LkkFile) CopyDir(source string, dest string, cover LkkFileCover) (int64, error)
  1102  ```
  1103  CopyDir 拷贝源目录到目标目录,cover为枚举(FILE_COVER_ALLOW、FILE_COVER_IGNORE、FILE_COVER_DENY).
  1104  
  1105  #### func (*LkkFile) CopyFile
  1106  
  1107  ```go
  1108  func (kf *LkkFile) CopyFile(source string, dest string, cover LkkFileCover) (int64, error)
  1109  ```
  1110  CopyFile
  1111  拷贝源文件到目标文件,cover为枚举(FILE_COVER_ALLOW、FILE_COVER_IGNORE、FILE_COVER_DENY).
  1112  
  1113  #### func (*LkkFile) CopyLink
  1114  
  1115  ```go
  1116  func (kf *LkkFile) CopyLink(source string, dest string) error
  1117  ```
  1118  CopyLink 拷贝链接.
  1119  
  1120  #### func (*LkkFile) CountLines
  1121  
  1122  ```go
  1123  func (kf *LkkFile) CountLines(fpath string, buffLength int) (int, error)
  1124  ```
  1125  CountLines 统计文件行数.buffLength为缓冲长度,kb.
  1126  
  1127  #### func (*LkkFile) DelDir
  1128  
  1129  ```go
  1130  func (kf *LkkFile) DelDir(dir string, delRoot bool) error
  1131  ```
  1132  DelDir 删除目录;delRoot为true时连该目录一起删除;为false时只清空该目录.
  1133  
  1134  #### func (*LkkFile) DirSize
  1135  
  1136  ```go
  1137  func (kf *LkkFile) DirSize(fpath string) int64
  1138  ```
  1139  DirSize 获取目录大小(bytes字节).
  1140  
  1141  #### func (*LkkFile) Dirname
  1142  
  1143  ```go
  1144  func (kf *LkkFile) Dirname(fpath string) string
  1145  ```
  1146  Dirname 返回路径中的目录部分,注意空路径或无目录的返回"." .
  1147  
  1148  #### func (*LkkFile) FastCopy
  1149  
  1150  ```go
  1151  func (kf *LkkFile) FastCopy(source string, dest string) (int64, error)
  1152  ```
  1153  FastCopy 快速拷贝源文件到目标文件,不做安全检查.
  1154  
  1155  #### func (*LkkFile) FileSize
  1156  
  1157  ```go
  1158  func (kf *LkkFile) FileSize(fpath string) int64
  1159  ```
  1160  FileSize 获取文件大小(bytes字节),注意:文件不存在或无法访问返回-1 .
  1161  
  1162  #### func (*LkkFile) FileTree
  1163  
  1164  ```go
  1165  func (kf *LkkFile) FileTree(fpath string, ftype LkkFileTree, recursive bool, filters ...FileFilter) []string
  1166  ```
  1167  FileTree 获取目录的文件树列表. ftype为枚举(FILE_TREE_ALL、FILE_TREE_DIR、FILE_TREE_FILE);
  1168  recursive为是否递归; filters为一个或多个文件过滤器函数,FileFilter类型.
  1169  
  1170  #### func (*LkkFile) FormatDir
  1171  
  1172  ```go
  1173  func (kf *LkkFile) FormatDir(fpath string) string
  1174  ```
  1175  FormatDir 格式化路径,将"\","//"替换为"/",且以"/"结尾.
  1176  
  1177  #### func (*LkkFile) GetExt
  1178  
  1179  ```go
  1180  func (kf *LkkFile) GetExt(fpath string) string
  1181  ```
  1182  GetExt 获取文件的小写扩展名,不包括点"." .
  1183  
  1184  #### func (*LkkFile) GetMime
  1185  
  1186  ```go
  1187  func (kf *LkkFile) GetMime(fpath string, fast bool) string
  1188  ```
  1189  GetMime 获取文件mime类型;fast为true时根据后缀快速获取;为false时读取文件头获取.
  1190  
  1191  #### func (*LkkFile) GetModTime
  1192  
  1193  ```go
  1194  func (kf *LkkFile) GetModTime(fpath string) (res int64)
  1195  ```
  1196  GetModTime 获取文件的修改时间戳,秒.
  1197  
  1198  #### func (*LkkFile) Glob
  1199  
  1200  ```go
  1201  func (kf *LkkFile) Glob(pattern string) ([]string, error)
  1202  ```
  1203  Glob 寻找与模式匹配的文件路径.
  1204  
  1205  #### func (*LkkFile) Img2Base64
  1206  
  1207  ```go
  1208  func (kf *LkkFile) Img2Base64(fpath string) (string, error)
  1209  ```
  1210  Img2Base64 读取图片文件,并转换为base64字符串.
  1211  
  1212  #### func (*LkkFile) IsBinary
  1213  
  1214  ```go
  1215  func (kf *LkkFile) IsBinary(fpath string) bool
  1216  ```
  1217  IsBinary 是否二进制文件(且存在).
  1218  
  1219  #### func (*LkkFile) IsDir
  1220  
  1221  ```go
  1222  func (kf *LkkFile) IsDir(fpath string) bool
  1223  ```
  1224  IsDir 是否目录(且存在).
  1225  
  1226  #### func (*LkkFile) IsExecutable
  1227  
  1228  ```go
  1229  func (kf *LkkFile) IsExecutable(fpath string) bool
  1230  ```
  1231  IsExecutable 是否可执行文件.
  1232  
  1233  #### func (*LkkFile) IsExist
  1234  
  1235  ```go
  1236  func (kf *LkkFile) IsExist(fpath string) bool
  1237  ```
  1238  IsExist 路径(文件/目录)是否存在.
  1239  
  1240  #### func (*LkkFile) IsFile
  1241  
  1242  ```go
  1243  func (kf *LkkFile) IsFile(fpath string) bool
  1244  ```
  1245  IsFile 是否常规文件(且存在).
  1246  
  1247  #### func (*LkkFile) IsImg
  1248  
  1249  ```go
  1250  func (kf *LkkFile) IsImg(fpath string) bool
  1251  ```
  1252  IsImg 是否图片文件(仅检查后缀).
  1253  
  1254  #### func (*LkkFile) IsLink
  1255  
  1256  ```go
  1257  func (kf *LkkFile) IsLink(fpath string) bool
  1258  ```
  1259  IsLink 是否链接文件(且存在).
  1260  
  1261  #### func (*LkkFile) IsReadable
  1262  
  1263  ```go
  1264  func (kf *LkkFile) IsReadable(fpath string) bool
  1265  ```
  1266  IsReadable 路径是否可读.
  1267  
  1268  #### func (*LkkFile) IsWritable
  1269  
  1270  ```go
  1271  func (kf *LkkFile) IsWritable(fpath string) bool
  1272  ```
  1273  IsWritable 路径是否可写.
  1274  
  1275  #### func (*LkkFile) IsZip
  1276  
  1277  ```go
  1278  func (kf *LkkFile) IsZip(fpath string) bool
  1279  ```
  1280  IsZip 是否zip文件夹.
  1281  
  1282  #### func (*LkkFile) Md5
  1283  
  1284  ```go
  1285  func (kf *LkkFile) Md5(fpath string, length uint8) (string, error)
  1286  ```
  1287  Md5 获取文件md5值,length指定结果长度32/16.
  1288  
  1289  #### func (*LkkFile) Mkdir
  1290  
  1291  ```go
  1292  func (kf *LkkFile) Mkdir(fpath string, mode os.FileMode) error
  1293  ```
  1294  Mkdir 新建目录,允许多级目录.
  1295  
  1296  #### func (*LkkFile) Pathinfo
  1297  
  1298  ```go
  1299  func (kf *LkkFile) Pathinfo(fpath string, options int) map[string]string
  1300  ```
  1301  Pathinfo 获取文件路径的信息,options的值为-1: all; 1: dirname; 2: basename; 4: extension; 8:
  1302  filename.
  1303  
  1304  #### func (*LkkFile) ReadFile
  1305  
  1306  ```go
  1307  func (kf *LkkFile) ReadFile(fpath string) ([]byte, error)
  1308  ```
  1309  ReadFile 读取文件内容.
  1310  
  1311  #### func (*LkkFile) ReadInArray
  1312  
  1313  ```go
  1314  func (kf *LkkFile) ReadInArray(fpath string) ([]string, error)
  1315  ```
  1316  ReadInArray 把整个文件读入一个数组中,每行作为一个元素.
  1317  
  1318  #### func (*LkkFile) RealPath
  1319  
  1320  ```go
  1321  func (kf *LkkFile) RealPath(fpath string) string
  1322  ```
  1323  RealPath 返回规范化的真实绝对路径名,path必须存在.若路径不存在则返回空字符串.
  1324  
  1325  #### func (*LkkFile) Rename
  1326  
  1327  ```go
  1328  func (kf *LkkFile) Rename(oldname, newname string) error
  1329  ```
  1330  Rename 重命名文件或目录.
  1331  
  1332  #### func (*LkkFile) SafeFileName
  1333  
  1334  ```go
  1335  func (kf *LkkFile) SafeFileName(str string) string
  1336  ```
  1337  SafeFileName 将文件名转换为安全可用的字符串.
  1338  
  1339  #### func (*LkkFile) ShaX
  1340  
  1341  ```go
  1342  func (kf *LkkFile) ShaX(fpath string, x uint16) (string, error)
  1343  ```
  1344  ShaX 计算文件的 shaX 散列值,x为1/256/512.
  1345  
  1346  #### func (*LkkFile) TarGz
  1347  
  1348  ```go
  1349  func (kf *LkkFile) TarGz(src string, dstTar string, ignorePatterns ...string) (bool, error)
  1350  ```
  1351  TarGz 打包压缩tar.gz;src为源文件或目录,dstTar为打包的路径名,ignorePatterns为要忽略的文件正则.
  1352  
  1353  #### func (*LkkFile) Touch
  1354  
  1355  ```go
  1356  func (kf *LkkFile) Touch(fpath string, size int64) bool
  1357  ```
  1358  Touch 快速创建指定大小的文件,size为字节.
  1359  
  1360  #### func (*LkkFile) UnTarGz
  1361  
  1362  ```go
  1363  func (kf *LkkFile) UnTarGz(srcTar, dstDir string) (bool, error)
  1364  ```
  1365  UnTarGz 将tar.gz文件解压缩;srcTar为压缩包,dstDir为解压目录.
  1366  
  1367  #### func (*LkkFile) UnZip
  1368  
  1369  ```go
  1370  func (kf *LkkFile) UnZip(srcZip, dstDir string) (bool, error)
  1371  ```
  1372  UnZip 解压zip文件.srcZip为zip文件路径,dstDir为解压目录.
  1373  
  1374  #### func (*LkkFile) Unlink
  1375  
  1376  ```go
  1377  func (kf *LkkFile) Unlink(fpath string) error
  1378  ```
  1379  Unlink 删除文件.
  1380  
  1381  #### func (*LkkFile) WriteFile
  1382  
  1383  ```go
  1384  func (kf *LkkFile) WriteFile(fpath string, data []byte) error
  1385  ```
  1386  WriteFile 将内容写入文件.
  1387  
  1388  #### func (*LkkFile) Zip
  1389  
  1390  ```go
  1391  func (kf *LkkFile) Zip(dst string, fpaths ...string) (bool, error)
  1392  ```
  1393  Zip 将文件目录进行zip打包.fpaths为文件或目录的路径.
  1394  
  1395  #### type LkkFileCover
  1396  
  1397  ```go
  1398  type LkkFileCover int8
  1399  ```
  1400  
  1401  LkkFileCover 枚举类型,文件是否覆盖
  1402  
  1403  #### type LkkFileTree
  1404  
  1405  ```go
  1406  type LkkFileTree int8
  1407  ```
  1408  
  1409  LkkFileTree 枚举类型,文件树查找类型
  1410  
  1411  #### type LkkNumber
  1412  
  1413  ```go
  1414  type LkkNumber byte
  1415  ```
  1416  
  1417  LkkNumber is the receiver of number utilities
  1418  
  1419  #### func (*LkkNumber) Abs
  1420  
  1421  ```go
  1422  func (kn *LkkNumber) Abs(number float64) float64
  1423  ```
  1424  Abs 取绝对值.
  1425  
  1426  #### func (*LkkNumber) Average
  1427  
  1428  ```go
  1429  func (kn *LkkNumber) Average(nums ...interface{}) (res float64)
  1430  ```
  1431  Average 对任意类型序列中的数值类型求平均值,忽略非数值的.
  1432  
  1433  #### func (*LkkNumber) AverageFloat64
  1434  
  1435  ```go
  1436  func (kn *LkkNumber) AverageFloat64(nums ...float64) (res float64)
  1437  ```
  1438  AverageFloat64 对浮点数序列求平均值.
  1439  
  1440  #### func (*LkkNumber) AverageInt
  1441  
  1442  ```go
  1443  func (kn *LkkNumber) AverageInt(nums ...int) (res float64)
  1444  ```
  1445  AverageInt 对整数序列求平均值.
  1446  
  1447  #### func (*LkkNumber) ByteFormat
  1448  
  1449  ```go
  1450  func (kn *LkkNumber) ByteFormat(size float64, decimal uint8) string
  1451  ```
  1452  ByteFormat 格式化文件比特大小. size为文件大小,decimal为要保留的小数位数.
  1453  
  1454  #### func (*LkkNumber) Ceil
  1455  
  1456  ```go
  1457  func (kn *LkkNumber) Ceil(value float64) float64
  1458  ```
  1459  Ceil 向上取整.
  1460  
  1461  #### func (*LkkNumber) Exp
  1462  
  1463  ```go
  1464  func (kn *LkkNumber) Exp(x float64) float64
  1465  ```
  1466  Exp 计算 e 的指数.
  1467  
  1468  #### func (*LkkNumber) Expm1
  1469  
  1470  ```go
  1471  func (kn *LkkNumber) Expm1(x float64) float64
  1472  ```
  1473  Expm1 返回 exp(number) - 1,甚至当 number 的值接近零也能计算出准确结果.
  1474  
  1475  #### func (*LkkNumber) FloatEqual
  1476  
  1477  ```go
  1478  func (kn *LkkNumber) FloatEqual(f1 float64, f2 float64, decimal ...int) bool
  1479  ```
  1480  FloatEqual 比较两个浮点数是否相等.decimal为小数精确位数.
  1481  
  1482  #### func (*LkkNumber) Floor
  1483  
  1484  ```go
  1485  func (kn *LkkNumber) Floor(value float64) float64
  1486  ```
  1487  Floor 向下取整.
  1488  
  1489  #### func (*LkkNumber) GeoDistance
  1490  
  1491  ```go
  1492  func (kn *LkkNumber) GeoDistance(lng1, lat1, lng2, lat2 float64) float64
  1493  ```
  1494  GeoDistance 获取地理距离/米. 参数分别为两点的经度和纬度.lat:-90~90,lng:-180~180.
  1495  
  1496  #### func (*LkkNumber) InRange
  1497  
  1498  ```go
  1499  func (kn *LkkNumber) InRange(value interface{}, left interface{}, right interface{}) bool
  1500  ```
  1501  InRange 数值是否在某个范围内,将自动转换类型再比较.
  1502  
  1503  #### func (*LkkNumber) InRangeFloat32
  1504  
  1505  ```go
  1506  func (kn *LkkNumber) InRangeFloat32(value, left, right float32) bool
  1507  ```
  1508  InRangeFloat32 数值是否在2个32位浮点数范围内.
  1509  
  1510  #### func (*LkkNumber) InRangeFloat64
  1511  
  1512  ```go
  1513  func (kn *LkkNumber) InRangeFloat64(value, left, right float64) bool
  1514  ```
  1515  InRangeFloat64 数值是否在2个64位浮点数范围内.
  1516  
  1517  #### func (*LkkNumber) InRangeInt
  1518  
  1519  ```go
  1520  func (kn *LkkNumber) InRangeInt(value, left, right int) bool
  1521  ```
  1522  InRangeInt 数值是否在2个整数范围内.
  1523  
  1524  #### func (*LkkNumber) IsEven
  1525  
  1526  ```go
  1527  func (kn *LkkNumber) IsEven(val int) bool
  1528  ```
  1529  IsEven 变量是否偶数.
  1530  
  1531  #### func (*LkkNumber) IsNan
  1532  
  1533  ```go
  1534  func (kn *LkkNumber) IsNan(val float64) bool
  1535  ```
  1536  IsNan 是否为“非数值”.
  1537  
  1538  #### func (*LkkNumber) IsNatural
  1539  
  1540  ```go
  1541  func (kn *LkkNumber) IsNatural(value float64) bool
  1542  ```
  1543  IsNatural 数值是否为自然数.
  1544  
  1545  #### func (*LkkNumber) IsNegative
  1546  
  1547  ```go
  1548  func (kn *LkkNumber) IsNegative(value float64) bool
  1549  ```
  1550  IsNegative 数值是否为负数.
  1551  
  1552  #### func (*LkkNumber) IsNonNegative
  1553  
  1554  ```go
  1555  func (kn *LkkNumber) IsNonNegative(value float64) bool
  1556  ```
  1557  IsNonNegative 数值是否为非负数.
  1558  
  1559  #### func (*LkkNumber) IsNonPositive
  1560  
  1561  ```go
  1562  func (kn *LkkNumber) IsNonPositive(value float64) bool
  1563  ```
  1564  IsNonPositive 数值是否为非正数.
  1565  
  1566  #### func (*LkkNumber) IsOdd
  1567  
  1568  ```go
  1569  func (kn *LkkNumber) IsOdd(val int) bool
  1570  ```
  1571  IsOdd 变量是否奇数.
  1572  
  1573  #### func (*LkkNumber) IsPositive
  1574  
  1575  ```go
  1576  func (kn *LkkNumber) IsPositive(value float64) bool
  1577  ```
  1578  IsPositive 数值是否为正数.
  1579  
  1580  #### func (*LkkNumber) IsWhole
  1581  
  1582  ```go
  1583  func (kn *LkkNumber) IsWhole(value float64) bool
  1584  ```
  1585  IsWhole 数值是否为整数.
  1586  
  1587  #### func (*LkkNumber) Max
  1588  
  1589  ```go
  1590  func (kn *LkkNumber) Max(nums ...interface{}) (res float64)
  1591  ```
  1592  Max 取出任意类型中数值类型的最大值,无数值类型则为0.
  1593  
  1594  #### func (*LkkNumber) MaxFloat64
  1595  
  1596  ```go
  1597  func (kn *LkkNumber) MaxFloat64(nums ...float64) (res float64)
  1598  ```
  1599  MaxFloat64 64位浮点数序列求最大值.
  1600  
  1601  #### func (*LkkNumber) MaxInt
  1602  
  1603  ```go
  1604  func (kn *LkkNumber) MaxInt(nums ...int) (res int)
  1605  ```
  1606  MaxInt 整数序列求最大值.
  1607  
  1608  #### func (*LkkNumber) Min
  1609  
  1610  ```go
  1611  func (kn *LkkNumber) Min(nums ...interface{}) (res float64)
  1612  ```
  1613  Min 取出任意类型中数值类型的最小值,无数值类型则为0.
  1614  
  1615  #### func (*LkkNumber) MinFloat64
  1616  
  1617  ```go
  1618  func (kn *LkkNumber) MinFloat64(nums ...float64) (res float64)
  1619  ```
  1620  MinFloat64 64位浮点数序列求最小值.
  1621  
  1622  #### func (*LkkNumber) MinInt
  1623  
  1624  ```go
  1625  func (kn *LkkNumber) MinInt(nums ...int) (res int)
  1626  ```
  1627  MinInt 整数序列求最小值.
  1628  
  1629  #### func (*LkkNumber) NumSign
  1630  
  1631  ```go
  1632  func (kn *LkkNumber) NumSign(value float64) float64
  1633  ```
  1634  NumSign 返回数值的符号.值>0为1,<0为-1,其他为0.
  1635  
  1636  #### func (*LkkNumber) NumberFormat
  1637  
  1638  ```go
  1639  func (kn *LkkNumber) NumberFormat(number float64, decimal uint8, point, thousand string) string
  1640  ```
  1641  NumberFormat 以千位分隔符方式格式化一个数字.
  1642  decimal为要保留的小数位数,point为小数点显示的字符,thousand为千位分隔符显示的字符.
  1643  
  1644  #### func (*LkkNumber) Pi
  1645  
  1646  ```go
  1647  func (kn *LkkNumber) Pi() float64
  1648  ```
  1649  Pi 得到圆周率值.
  1650  
  1651  #### func (*LkkNumber) Pow
  1652  
  1653  ```go
  1654  func (kn *LkkNumber) Pow(x, y float64) float64
  1655  ```
  1656  Pow 指数表达式.
  1657  
  1658  #### func (*LkkNumber) Rand
  1659  
  1660  ```go
  1661  func (kn *LkkNumber) Rand(min, max int) int
  1662  ```
  1663  Rand RandInt的别名.
  1664  
  1665  #### func (*LkkNumber) RandFloat64
  1666  
  1667  ```go
  1668  func (kn *LkkNumber) RandFloat64(min, max float64) float64
  1669  ```
  1670  RandFloat64 生产一个随机float64整数.
  1671  
  1672  #### func (*LkkNumber) RandInt
  1673  
  1674  ```go
  1675  func (kn *LkkNumber) RandInt(min, max int) int
  1676  ```
  1677  RandInt 产生一个随机int整数.
  1678  
  1679  #### func (*LkkNumber) RandInt64
  1680  
  1681  ```go
  1682  func (kn *LkkNumber) RandInt64(min, max int64) int64
  1683  ```
  1684  RandInt64 生产一个随机int64整数.
  1685  
  1686  #### func (*LkkNumber) Range
  1687  
  1688  ```go
  1689  func (kn *LkkNumber) Range(min, max int) []int
  1690  ```
  1691  Range 根据范围创建数组,包含指定的元素.
  1692  
  1693  #### func (*LkkNumber) Round
  1694  
  1695  ```go
  1696  func (kn *LkkNumber) Round(value float64) float64
  1697  ```
  1698  Round 对浮点数进行四舍五入.
  1699  
  1700  #### func (*LkkNumber) Sum
  1701  
  1702  ```go
  1703  func (kn *LkkNumber) Sum(nums ...interface{}) (res float64)
  1704  ```
  1705  Sum 对任意类型序列中的数值类型求和,忽略非数值的.
  1706  
  1707  #### func (*LkkNumber) SumFloat64
  1708  
  1709  ```go
  1710  func (kn *LkkNumber) SumFloat64(nums ...float64) float64
  1711  ```
  1712  SumFloat64 浮点数求和.
  1713  
  1714  #### func (*LkkNumber) SumInt
  1715  
  1716  ```go
  1717  func (kn *LkkNumber) SumInt(nums ...int) int
  1718  ```
  1719  SumInt 整数求和.
  1720  
  1721  #### type LkkOS
  1722  
  1723  ```go
  1724  type LkkOS byte
  1725  ```
  1726  
  1727  LkkOS is the receiver of OS utilities
  1728  
  1729  #### func (*LkkOS) Chdir
  1730  
  1731  ```go
  1732  func (ko *LkkOS) Chdir(dir string) error
  1733  ```
  1734  Chdir 改变/进入新的工作目录.
  1735  
  1736  #### func (*LkkOS) Chmod
  1737  
  1738  ```go
  1739  func (ko *LkkOS) Chmod(filename string, mode os.FileMode) bool
  1740  ```
  1741  Chmod 改变文件模式.
  1742  
  1743  #### func (*LkkOS) Chown
  1744  
  1745  ```go
  1746  func (ko *LkkOS) Chown(filename string, uid, gid int) bool
  1747  ```
  1748  Chown 改变文件的所有者.
  1749  
  1750  #### func (*LkkOS) ClientIp
  1751  
  1752  ```go
  1753  func (ko *LkkOS) ClientIp(req *http.Request) string
  1754  ```
  1755  ClientIp 获取客户端真实IP,req为http请求.
  1756  
  1757  #### func (*LkkOS) CpuUsage
  1758  
  1759  ```go
  1760  func (ko *LkkOS) CpuUsage() (user, idle, total uint64)
  1761  ```
  1762  CpuUsage 获取CPU使用率(仅支持linux),单位jiffies(节拍数). user为用户态(用户进程)的运行时间, idle为空闲时间,
  1763  total为累计时间.
  1764  
  1765  #### func (*LkkOS) DiskUsage
  1766  
  1767  ```go
  1768  func (ko *LkkOS) DiskUsage(path string) (used, free, total uint64)
  1769  ```
  1770  DiskUsage 获取磁盘/目录使用情况,单位字节.参数path为目录. used为已用, free为空闲, total为总数.
  1771  
  1772  #### func (*LkkOS) Exec
  1773  
  1774  ```go
  1775  func (ko *LkkOS) Exec(command string) (retInt int, outStr, errStr []byte)
  1776  ```
  1777  Exec 执行一个外部命令. retInt为1时失败,为0时成功;outStr为执行命令的输出;errStr为错误输出. 命令如 "ls -a"
  1778  "/bin/bash -c \"ls -a\""
  1779  
  1780  #### func (*LkkOS) ForceGC
  1781  
  1782  ```go
  1783  func (ko *LkkOS) ForceGC()
  1784  ```
  1785  ForceGC 强制手动GC垃圾回收(阻塞).
  1786  
  1787  #### func (*LkkOS) GetEndian
  1788  
  1789  ```go
  1790  func (ko *LkkOS) GetEndian() binary.ByteOrder
  1791  ```
  1792  GetEndian 获取系统字节序类型,小端返回binary.LittleEndian,大端返回binary.BigEndian .
  1793  
  1794  #### func (*LkkOS) GetHostByIp
  1795  
  1796  ```go
  1797  func (ko *LkkOS) GetHostByIp(ipAddress string) (string, error)
  1798  ```
  1799  GetHostByIp 获取指定的IP地址对应的主机名.
  1800  
  1801  #### func (*LkkOS) GetIPs
  1802  
  1803  ```go
  1804  func (ko *LkkOS) GetIPs() (ips []string)
  1805  ```
  1806  GetIPs 获取本机的IP列表.
  1807  
  1808  #### func (*LkkOS) GetIpByHostname
  1809  
  1810  ```go
  1811  func (ko *LkkOS) GetIpByHostname(hostname string) (string, error)
  1812  ```
  1813  GetIpByHostname 返回主机名对应的 IPv4地址.
  1814  
  1815  #### func (*LkkOS) GetIpsByDomain
  1816  
  1817  ```go
  1818  func (ko *LkkOS) GetIpsByDomain(domain string) ([]string, error)
  1819  ```
  1820  GetIpsByHost 获取互联网域名/主机名对应的 IPv4 地址列表.
  1821  
  1822  #### func (*LkkOS) GetMacAddrs
  1823  
  1824  ```go
  1825  func (ko *LkkOS) GetMacAddrs() (macAddrs []string)
  1826  ```
  1827  GetMacAddrs 获取本机的Mac网卡地址列表.
  1828  
  1829  #### func (*LkkOS) GetPidByPort
  1830  
  1831  ```go
  1832  func (ko *LkkOS) GetPidByPort(port int) (pid int)
  1833  ```
  1834  GetPidByPort 根据端口号获取监听的进程PID.
  1835  
  1836  #### func (*LkkOS) GetProcessExeByPid
  1837  
  1838  ```go
  1839  func (ko *LkkOS) GetProcessExeByPid(pid int) string
  1840  ```
  1841  GetProcessExeByPid 根据PID获取进程的执行路径.
  1842  
  1843  #### func (*LkkOS) GetSystemInfo
  1844  
  1845  ```go
  1846  func (ko *LkkOS) GetSystemInfo() *SystemInfo
  1847  ```
  1848  GetSystemInfo 获取系统运行信息.
  1849  
  1850  #### func (*LkkOS) GetTempDir
  1851  
  1852  ```go
  1853  func (ko *LkkOS) GetTempDir() string
  1854  ```
  1855  GetTempDir 返回用于临时文件的目录.
  1856  
  1857  #### func (*LkkOS) Getcwd
  1858  
  1859  ```go
  1860  func (ko *LkkOS) Getcwd() (string, error)
  1861  ```
  1862  Getcwd 取得当前工作目录(程序可能在任务中进行多次目录切换).
  1863  
  1864  #### func (*LkkOS) Getenv
  1865  
  1866  ```go
  1867  func (ko *LkkOS) Getenv(varname string) string
  1868  ```
  1869  Getenv 获取一个环境变量的值.
  1870  
  1871  #### func (*LkkOS) GoMemory
  1872  
  1873  ```go
  1874  func (ko *LkkOS) GoMemory() uint64
  1875  ```
  1876  MemoryGetUsage 获取当前go程序的内存使用,返回字节数.
  1877  
  1878  #### func (*LkkOS) HomeDir
  1879  
  1880  ```go
  1881  func (ko *LkkOS) HomeDir() (string, error)
  1882  ```
  1883  HomeDir 获取当前用户的主目录(仅支持Unix-like system).
  1884  
  1885  #### func (*LkkOS) Hostname
  1886  
  1887  ```go
  1888  func (ko *LkkOS) Hostname() (string, error)
  1889  ```
  1890  Hostname 获取主机名.
  1891  
  1892  #### func (*LkkOS) IsLinux
  1893  
  1894  ```go
  1895  func (ko *LkkOS) IsLinux() bool
  1896  ```
  1897  IsLinux 当前操作系统是否Linux.
  1898  
  1899  #### func (*LkkOS) IsLittleEndian
  1900  
  1901  ```go
  1902  func (ko *LkkOS) IsLittleEndian() bool
  1903  ```
  1904  IsLittleEndian 系统字节序类型是否小端存储.
  1905  
  1906  #### func (*LkkOS) IsMac
  1907  
  1908  ```go
  1909  func (ko *LkkOS) IsMac() bool
  1910  ```
  1911  IsMac 当前操作系统是否Mac OS/X.
  1912  
  1913  #### func (*LkkOS) IsPortOpen
  1914  
  1915  ```go
  1916  func (ko *LkkOS) IsPortOpen(host string, port interface{}, protocols ...string) bool
  1917  ```
  1918  IsPortOpen 检查主机端口是否开放.protocols为协议名称,可选,默认tcp.
  1919  
  1920  #### func (*LkkOS) IsPrivateIp
  1921  
  1922  ```go
  1923  func (ko *LkkOS) IsPrivateIp(address string) (bool, error)
  1924  ```
  1925  IsPrivateIp 是否私有IP地址(ipv4/ipv6).
  1926  
  1927  #### func (*LkkOS) IsPublicIP
  1928  
  1929  ```go
  1930  func (ko *LkkOS) IsPublicIP(ip net.IP) bool
  1931  ```
  1932  IsPublicIP 是否公网IP.
  1933  
  1934  #### func (*LkkOS) IsWindows
  1935  
  1936  ```go
  1937  func (ko *LkkOS) IsWindows() bool
  1938  ```
  1939  IsWindows 当前操作系统是否Windows.
  1940  
  1941  #### func (*LkkOS) LocalIP
  1942  
  1943  ```go
  1944  func (ko *LkkOS) LocalIP() (string, error)
  1945  ```
  1946  LocalIP 获取本机第一个NIC's IP.
  1947  
  1948  #### func (*LkkOS) MemoryUsage
  1949  
  1950  ```go
  1951  func (ko *LkkOS) MemoryUsage(virtual bool) (used, free, total uint64)
  1952  ```
  1953  MemoryUsage 获取内存使用率(仅支持linux),单位字节. 参数 virtual,是否取虚拟内存. used为已用, free为空闲,
  1954  total为总数.
  1955  
  1956  #### func (*LkkOS) OutboundIP
  1957  
  1958  ```go
  1959  func (ko *LkkOS) OutboundIP() (string, error)
  1960  ```
  1961  OutboundIP 获取本机的出口IP.
  1962  
  1963  #### func (*LkkOS) PrivateCIDR
  1964  
  1965  ```go
  1966  func (ko *LkkOS) PrivateCIDR() []*net.IPNet
  1967  ```
  1968  PrivateCIDR 获取私有网段的CIDR(无类别域间路由).
  1969  
  1970  #### func (*LkkOS) Pwd
  1971  
  1972  ```go
  1973  func (ko *LkkOS) Pwd() string
  1974  ```
  1975  Pwd 获取当前程序运行所在的路径,注意和Getwd有所不同.
  1976  
  1977  #### func (*LkkOS) Setenv
  1978  
  1979  ```go
  1980  func (ko *LkkOS) Setenv(varname, data string) error
  1981  ```
  1982  Setenv 设置一个环境变量的值.
  1983  
  1984  #### func (*LkkOS) System
  1985  
  1986  ```go
  1987  func (ko *LkkOS) System(command string) (retInt int, outStr, errStr []byte)
  1988  ```
  1989  System 与Exec相同,但会同时打印标准输出和标准错误.
  1990  
  1991  #### func (*LkkOS) TriggerGC
  1992  
  1993  ```go
  1994  func (ko *LkkOS) TriggerGC()
  1995  ```
  1996  TriggerGC 触发GC(非阻塞).
  1997  
  1998  #### type LkkPadType
  1999  
  2000  ```go
  2001  type LkkPadType uint8
  2002  ```
  2003  
  2004  LkkPadType 枚举类型,字符串填充类型
  2005  
  2006  #### type LkkRandString
  2007  
  2008  ```go
  2009  type LkkRandString uint8
  2010  ```
  2011  
  2012  LkkRandString 枚举类型,随机字符串类型
  2013  
  2014  #### type LkkString
  2015  
  2016  ```go
  2017  type LkkString byte
  2018  ```
  2019  
  2020  LkkString is the receiver of string utilities
  2021  
  2022  #### func (*LkkString) Addslashes
  2023  
  2024  ```go
  2025  func (ks *LkkString) Addslashes(str string) string
  2026  ```
  2027  Addslashes 使用反斜线引用字符串.
  2028  
  2029  #### func (*LkkString) Big5ToUtf8
  2030  
  2031  ```go
  2032  func (ks *LkkString) Big5ToUtf8(s []byte) ([]byte, error)
  2033  ```
  2034  Big5ToUtf8 BIG5转UTF-8编码.
  2035  
  2036  #### func (*LkkString) Br2nl
  2037  
  2038  ```go
  2039  func (ks *LkkString) Br2nl(str string) string
  2040  ```
  2041  Br2nl 将br标签转换为换行符.
  2042  
  2043  #### func (*LkkString) Chr
  2044  
  2045  ```go
  2046  func (ks *LkkString) Chr(ascii int) string
  2047  ```
  2048  Chr 返回相对应于 ascii 所指定的单个字符.
  2049  
  2050  #### func (*LkkString) ChunkSplit
  2051  
  2052  ```go
  2053  func (ks *LkkString) ChunkSplit(str string, chunklen uint, end string) string
  2054  ```
  2055  ChunkSplit 将字符串分割成小块.str为要分割的字符,chunklen为分割的尺寸,end为行尾序列符号.
  2056  
  2057  #### func (*LkkString) ClosestWord
  2058  
  2059  ```go
  2060  func (ks *LkkString) ClosestWord(word string, searchs []string) (string, int)
  2061  ```
  2062  ClosestWord 获取与原字符串相似度最高的字符串,以及它们的编辑距离. word为原字符串,searchs为待查找的字符串数组.
  2063  
  2064  #### func (*LkkString) CountBase64Byte
  2065  
  2066  ```go
  2067  func (ks *LkkString) CountBase64Byte(str string) (res int)
  2068  ```
  2069  CountBase64Byte 统计base64字符串大小,字节.
  2070  
  2071  #### func (*LkkString) CountWords
  2072  
  2073  ```go
  2074  func (ks *LkkString) CountWords(str string) (int, map[string]int)
  2075  ```
  2076  CountWords 统计字符串中单词的使用情况. 返回结果:单词总数;和一个字典,包含每个单词的单独统计. 因为没有分词,对中文尚未很好支持.
  2077  
  2078  #### func (*LkkString) Crc32
  2079  
  2080  ```go
  2081  func (ks *LkkString) Crc32(str string) uint32
  2082  ```
  2083  Crc32 计算一个字符串的 crc32 多项式.
  2084  
  2085  #### func (*LkkString) DBC2SBC
  2086  
  2087  ```go
  2088  func (ks *LkkString) DBC2SBC(s string) string
  2089  ```
  2090  DBC2SBC 半角转全角.
  2091  
  2092  #### func (*LkkString) Dstrpos
  2093  
  2094  ```go
  2095  func (ks *LkkString) Dstrpos(str string, arr []string, chkCase bool) (bool, string)
  2096  ```
  2097  Dstrpos 检查字符串str是否包含数组arr的元素之一,返回检查结果和匹配的字符串. chkCase为是否检查大小写.
  2098  
  2099  #### func (*LkkString) EndsWith
  2100  
  2101  ```go
  2102  func (ks *LkkString) EndsWith(str, substr string) bool
  2103  ```
  2104  EndsWith 字符串str是否以substr结尾.
  2105  
  2106  #### func (*LkkString) Explode
  2107  
  2108  ```go
  2109  func (ks *LkkString) Explode(str string, delimiters ...string) (res []string)
  2110  ```
  2111  Explode 字符串分割.delimiters为分隔符,可选,支持多个.
  2112  
  2113  #### func (*LkkString) FirstLetter
  2114  
  2115  ```go
  2116  func (ks *LkkString) FirstLetter(str string) string
  2117  ```
  2118  FirstLetter 获取字符串首字母.
  2119  
  2120  #### func (*LkkString) FormatUrl
  2121  
  2122  ```go
  2123  func (ks *LkkString) FormatUrl(str string) string
  2124  ```
  2125  FormatUrl 格式化URL.
  2126  
  2127  #### func (*LkkString) GbkToUtf8
  2128  
  2129  ```go
  2130  func (ks *LkkString) GbkToUtf8(s []byte) ([]byte, error)
  2131  ```
  2132  GbkToUtf8 GBK转UTF-8编码.
  2133  
  2134  #### func (*LkkString) GetDomain
  2135  
  2136  ```go
  2137  func (ks *LkkString) GetDomain(str string, isMains ...bool) string
  2138  ```
  2139  GetDomain 从URL字符串中获取域名.
  2140  可选参数isMains,默认为false,取完整域名;为true时,取主域名(如abc.test.com取test.com).
  2141  
  2142  #### func (*LkkString) HasChinese
  2143  
  2144  ```go
  2145  func (ks *LkkString) HasChinese(str string) bool
  2146  ```
  2147  HasChinese 字符串是否含有中文.
  2148  
  2149  #### func (*LkkString) HasEnglish
  2150  
  2151  ```go
  2152  func (ks *LkkString) HasEnglish(str string) bool
  2153  ```
  2154  HasEnglish 是否含有英文字符,HasLetter的别名.
  2155  
  2156  #### func (*LkkString) HasFullWidth
  2157  
  2158  ```go
  2159  func (ks *LkkString) HasFullWidth(str string) bool
  2160  ```
  2161  HasFullWidth 是否含有全角字符.
  2162  
  2163  #### func (*LkkString) HasHalfWidth
  2164  
  2165  ```go
  2166  func (ks *LkkString) HasHalfWidth(str string) bool
  2167  ```
  2168  HasHalfWidth 是否含有半角字符.
  2169  
  2170  #### func (*LkkString) HasLetter
  2171  
  2172  ```go
  2173  func (ks *LkkString) HasLetter(str string) bool
  2174  ```
  2175  HasLetter 字符串是否含有(英文)字母.
  2176  
  2177  #### func (*LkkString) HasSpecialChar
  2178  
  2179  ```go
  2180  func (ks *LkkString) HasSpecialChar(str string) (res bool)
  2181  ```
  2182  HasSpecialChar 字符串是否含有特殊字符.
  2183  
  2184  #### func (*LkkString) HasWhitespace
  2185  
  2186  ```go
  2187  func (ks *LkkString) HasWhitespace(str string) bool
  2188  ```
  2189  HasWhitespace 是否带有空白字符.
  2190  
  2191  #### func (*LkkString) HideCard
  2192  
  2193  ```go
  2194  func (ks *LkkString) HideCard(card string) string
  2195  ```
  2196  HideCard 隐藏证件号码.
  2197  
  2198  #### func (*LkkString) HideMobile
  2199  
  2200  ```go
  2201  func (ks *LkkString) HideMobile(mobile string) string
  2202  ```
  2203  HideMobile 隐藏手机号.
  2204  
  2205  #### func (*LkkString) HideTrueName
  2206  
  2207  ```go
  2208  func (ks *LkkString) HideTrueName(name string) string
  2209  ```
  2210  HideTrueName 隐藏真实名称(如姓名、账号、公司等).
  2211  
  2212  #### func (*LkkString) Html2Text
  2213  
  2214  ```go
  2215  func (ks *LkkString) Html2Text(str string) string
  2216  ```
  2217  Html2Text 将html转换为纯文本.
  2218  
  2219  #### func (*LkkString) Htmlentities
  2220  
  2221  ```go
  2222  func (ks *LkkString) Htmlentities(str string) string
  2223  ```
  2224  Htmlentities 将字符转换为 HTML 转义字符.
  2225  
  2226  #### func (*LkkString) HtmlentityDecode
  2227  
  2228  ```go
  2229  func (ks *LkkString) HtmlentityDecode(str string) string
  2230  ```
  2231  HtmlentityDecode 将HTML实体转换为它们对应的字符.
  2232  
  2233  #### func (*LkkString) HttpBuildQuery
  2234  
  2235  ```go
  2236  func (ks *LkkString) HttpBuildQuery(queryData url.Values) string
  2237  ```
  2238  HttpBuildQuery 根据参数生成 URL-encode 之后的请求字符串.
  2239  
  2240  #### func (*LkkString) Img2Base64
  2241  
  2242  ```go
  2243  func (ks *LkkString) Img2Base64(content []byte, ext ...string) string
  2244  ```
  2245  Img2Base64 将字符串转换为base64图片.ext为图片扩展名,默认jpg.
  2246  
  2247  #### func (*LkkString) IsASCII
  2248  
  2249  ```go
  2250  func (ks *LkkString) IsASCII(str string) bool
  2251  ```
  2252  IsASCII 是否IsASCII字符串.
  2253  
  2254  #### func (*LkkString) IsAlphaNumeric
  2255  
  2256  ```go
  2257  func (ks *LkkString) IsAlphaNumeric(str string) bool
  2258  ```
  2259  IsAlphaNumeric 是否字母或数字.
  2260  
  2261  #### func (*LkkString) IsBase64
  2262  
  2263  ```go
  2264  func (ks *LkkString) IsBase64(str string) bool
  2265  ```
  2266  IsBase64 是否base64字符串.
  2267  
  2268  #### func (*LkkString) IsBase64Image
  2269  
  2270  ```go
  2271  func (ks *LkkString) IsBase64Image(str string) bool
  2272  ```
  2273  IsBase64Image 是否base64编码的图片.
  2274  
  2275  #### func (*LkkString) IsBlank
  2276  
  2277  ```go
  2278  func (ks *LkkString) IsBlank(str string) bool
  2279  ```
  2280  IsBlank 是否空(空白)字符.
  2281  
  2282  #### func (*LkkString) IsChinese
  2283  
  2284  ```go
  2285  func (ks *LkkString) IsChinese(str string) bool
  2286  ```
  2287  IsChinese 字符串是否全部中文.
  2288  
  2289  #### func (*LkkString) IsChineseName
  2290  
  2291  ```go
  2292  func (ks *LkkString) IsChineseName(str string) bool
  2293  ```
  2294  IsChineseName 字符串是否中文名称.
  2295  
  2296  #### func (*LkkString) IsCreditNo
  2297  
  2298  ```go
  2299  func (ks *LkkString) IsCreditNo(str string) (bool, string)
  2300  ```
  2301  IsCreditNo 检查是否(15或18位)身份证号码,并返回经校验的号码.
  2302  
  2303  #### func (*LkkString) IsDNSName
  2304  
  2305  ```go
  2306  func (ks *LkkString) IsDNSName(str string) bool
  2307  ```
  2308  IsDNSName 是否DNS名称.
  2309  
  2310  #### func (*LkkString) IsDialString
  2311  
  2312  ```go
  2313  func (ks *LkkString) IsDialString(str string) bool
  2314  ```
  2315  IsDialString 是否网络拨号字符串(形如127.0.0.1:80),用于net.Dial()检查.
  2316  
  2317  #### func (*LkkString) IsEmail
  2318  
  2319  ```go
  2320  func (ks *LkkString) IsEmail(email string, validateHost bool) (bool, error)
  2321  ```
  2322  IsEmail 检查字符串是否邮箱.参数validateTrue,是否验证邮箱主机的真实性.
  2323  
  2324  #### func (*LkkString) IsEmpty
  2325  
  2326  ```go
  2327  func (ks *LkkString) IsEmpty(str string) bool
  2328  ```
  2329  IsEmpty 字符串是否为空(包括空格).
  2330  
  2331  #### func (*LkkString) IsEnglish
  2332  
  2333  ```go
  2334  func (ks *LkkString) IsEnglish(str string, letterCase LkkCaseSwitch) bool
  2335  ```
  2336  IsEnglish 字符串是否纯英文.letterCase是否检查大小写,枚举值(CASE_NONE,CASE_LOWER,CASE_UPPER).
  2337  
  2338  #### func (*LkkString) IsHexcolor
  2339  
  2340  ```go
  2341  func (ks *LkkString) IsHexcolor(str string) (bool, string)
  2342  ```
  2343  IsHexcolor 检查是否十六进制颜色,并返回带"#"的修正值.
  2344  
  2345  #### func (*LkkString) IsHost
  2346  
  2347  ```go
  2348  func (ks *LkkString) IsHost(str string) bool
  2349  ```
  2350  IsHost 字符串是否主机名(IP或DNS名称).
  2351  
  2352  #### func (*LkkString) IsIP
  2353  
  2354  ```go
  2355  func (ks *LkkString) IsIP(str string) bool
  2356  ```
  2357  IsIP 检查字符串是否IP地址.
  2358  
  2359  #### func (*LkkString) IsIPv4
  2360  
  2361  ```go
  2362  func (ks *LkkString) IsIPv4(str string) bool
  2363  ```
  2364  IsIPv4 检查字符串是否IPv4地址.
  2365  
  2366  #### func (*LkkString) IsIPv6
  2367  
  2368  ```go
  2369  func (ks *LkkString) IsIPv6(str string) bool
  2370  ```
  2371  IsIPv6 检查字符串是否IPv6地址.
  2372  
  2373  #### func (*LkkString) IsJSON
  2374  
  2375  ```go
  2376  func (ks *LkkString) IsJSON(str string) bool
  2377  ```
  2378  IsJSON 字符串是否合法的json格式.
  2379  
  2380  #### func (*LkkString) IsLetters
  2381  
  2382  ```go
  2383  func (ks *LkkString) IsLetters(str string) bool
  2384  ```
  2385  IsLetters 字符串是否全(英文)字母组成.
  2386  
  2387  #### func (*LkkString) IsLower
  2388  
  2389  ```go
  2390  func (ks *LkkString) IsLower(str string) bool
  2391  ```
  2392  IsLower 字符串是否全部小写.
  2393  
  2394  #### func (*LkkString) IsMACAddr
  2395  
  2396  ```go
  2397  func (ks *LkkString) IsMACAddr(str string) bool
  2398  ```
  2399  IsMACAddr 是否MAC物理网卡地址.
  2400  
  2401  #### func (*LkkString) IsMd5
  2402  
  2403  ```go
  2404  func (ks *LkkString) IsMd5(str string) bool
  2405  ```
  2406  IsMd5 是否md5值.
  2407  
  2408  #### func (*LkkString) IsMobilecn
  2409  
  2410  ```go
  2411  func (ks *LkkString) IsMobilecn(str string) bool
  2412  ```
  2413  IsMobilecn 检查字符串是否中国大陆手机号.
  2414  
  2415  #### func (*LkkString) IsMultibyte
  2416  
  2417  ```go
  2418  func (ks *LkkString) IsMultibyte(str string) bool
  2419  ```
  2420  IsMultibyte 字符串是否含有多字节字符.
  2421  
  2422  #### func (*LkkString) IsPhone
  2423  
  2424  ```go
  2425  func (ks *LkkString) IsPhone(str string) bool
  2426  ```
  2427  IsPhone 是否电话号码(手机或固话).
  2428  
  2429  #### func (*LkkString) IsPort
  2430  
  2431  ```go
  2432  func (ks *LkkString) IsPort(val interface{}) bool
  2433  ```
  2434  IsPort 字符串或数字是否端口号.
  2435  
  2436  #### func (*LkkString) IsRGBcolor
  2437  
  2438  ```go
  2439  func (ks *LkkString) IsRGBcolor(str string) bool
  2440  ```
  2441  IsRGBcolor 检查字符串是否RGB颜色格式.
  2442  
  2443  #### func (*LkkString) IsRsaPublicKey
  2444  
  2445  ```go
  2446  func (ks *LkkString) IsRsaPublicKey(str string, keylen int) bool
  2447  ```
  2448  IsRsaPublicKey 检查字符串是否RSA的公钥,keylen为密钥长度.
  2449  
  2450  #### func (*LkkString) IsSha1
  2451  
  2452  ```go
  2453  func (ks *LkkString) IsSha1(str string) bool
  2454  ```
  2455  IsSha1 是否Sha1值.
  2456  
  2457  #### func (*LkkString) IsSha256
  2458  
  2459  ```go
  2460  func (ks *LkkString) IsSha256(str string) bool
  2461  ```
  2462  IsSha256 是否Sha256值.
  2463  
  2464  #### func (*LkkString) IsSha512
  2465  
  2466  ```go
  2467  func (ks *LkkString) IsSha512(str string) bool
  2468  ```
  2469  IsSha512 是否Sha512值.
  2470  
  2471  #### func (*LkkString) IsTel
  2472  
  2473  ```go
  2474  func (ks *LkkString) IsTel(str string) bool
  2475  ```
  2476  IsTel 是否固定电话或400/800电话.
  2477  
  2478  #### func (*LkkString) IsUpper
  2479  
  2480  ```go
  2481  func (ks *LkkString) IsUpper(str string) bool
  2482  ```
  2483  IsUpper 字符串是否全部大写.
  2484  
  2485  #### func (*LkkString) IsUrl
  2486  
  2487  ```go
  2488  func (ks *LkkString) IsUrl(str string) bool
  2489  ```
  2490  IsUrl 检查字符串是否URL.
  2491  
  2492  #### func (*LkkString) IsUrlExists
  2493  
  2494  ```go
  2495  func (ks *LkkString) IsUrlExists(str string) bool
  2496  ```
  2497  IsUrlExists 检查URL是否存在.
  2498  
  2499  #### func (*LkkString) IsUtf8
  2500  
  2501  ```go
  2502  func (ks *LkkString) IsUtf8(str string) bool
  2503  ```
  2504  IsUtf8 字符串是否UTF-8编码.
  2505  
  2506  #### func (*LkkString) IsWhitespaces
  2507  
  2508  ```go
  2509  func (ks *LkkString) IsWhitespaces(str string) bool
  2510  ```
  2511  IsWhitespaces 是否全部空白字符,不包括空字符串.
  2512  
  2513  #### func (*LkkString) JsonDecode
  2514  
  2515  ```go
  2516  func (ks *LkkString) JsonDecode(data []byte, val interface{}) error
  2517  ```
  2518  JsonDecode 对 JSON 格式的字符串进行解码,注意val使用指针. 依赖库github.com/json-iterator/go.
  2519  
  2520  #### func (*LkkString) JsonEncode
  2521  
  2522  ```go
  2523  func (ks *LkkString) JsonEncode(val interface{}) ([]byte, error)
  2524  ```
  2525  JsonEncode 对变量进行 JSON 编码. 依赖库github.com/json-iterator/go.
  2526  
  2527  #### func (*LkkString) Jsonp2Json
  2528  
  2529  ```go
  2530  func (ks *LkkString) Jsonp2Json(str string) (string, error)
  2531  ```
  2532  Jsonp2Json 将jsonp转为json串. Example: forbar({a:"1",b:2}) to {"a":"1","b":2}
  2533  
  2534  #### func (*LkkString) Lcfirst
  2535  
  2536  ```go
  2537  func (ks *LkkString) Lcfirst(str string) string
  2538  ```
  2539  Lcfirst 将字符串的第一个字符转换为小写.
  2540  
  2541  #### func (*LkkString) Lcwords
  2542  
  2543  ```go
  2544  func (ks *LkkString) Lcwords(str string) string
  2545  ```
  2546  Lcwords 将字符串中每个词的首字母转换为小写.
  2547  
  2548  #### func (*LkkString) Levenshtein
  2549  
  2550  ```go
  2551  func (ks *LkkString) Levenshtein(a, b *string) int
  2552  ```
  2553  Levenshtein 计算两个字符串之间的编辑距离.
  2554  
  2555  #### func (*LkkString) Ltrim
  2556  
  2557  ```go
  2558  func (ks *LkkString) Ltrim(str string, characterMask ...string) string
  2559  ```
  2560  Ltrim 删除字符串开头的空白字符(或其他字符).
  2561  
  2562  #### func (*LkkString) MbStrlen
  2563  
  2564  ```go
  2565  func (ks *LkkString) MbStrlen(str string) int
  2566  ```
  2567  MbStrlen 获取宽字符串的长度,多字节的字符被计为 1.
  2568  
  2569  #### func (*LkkString) MbSubstr
  2570  
  2571  ```go
  2572  func (ks *LkkString) MbSubstr(str string, start int, length ...int) string
  2573  ```
  2574  MbSubstr 返回(宽字符)字符串str的子串. start 为起始位置.若值是负数,返回的结果将从 str 结尾处向前数第 abs(start)
  2575  个字符开始. length 为截取的长度.若值时负数, str 末尾处的 abs(length) 个字符将会被省略.
  2576  start/length的绝对值必须<=原字符串长度.
  2577  
  2578  #### func (*LkkString) Md5
  2579  
  2580  ```go
  2581  func (ks *LkkString) Md5(str string, length uint8) string
  2582  ```
  2583  Md5 获取字符串md5值,length指定结果长度32/16 .
  2584  
  2585  #### func (*LkkString) Nl2br
  2586  
  2587  ```go
  2588  func (ks *LkkString) Nl2br(html string) string
  2589  ```
  2590  Nl2br 将换行符转换为br标签.
  2591  
  2592  #### func (*LkkString) Ord
  2593  
  2594  ```go
  2595  func (ks *LkkString) Ord(char string) rune
  2596  ```
  2597  Ord 将首字符转换为rune.
  2598  
  2599  #### func (*LkkString) ParseStr
  2600  
  2601  ```go
  2602  func (ks *LkkString) ParseStr(encodedString string, result map[string]interface{}) error
  2603  ```
  2604  ParseStr 将查询字符串转换为字典.
  2605  
  2606  #### func (*LkkString) ParseUrl
  2607  
  2608  ```go
  2609  func (ks *LkkString) ParseUrl(str string, component int) (map[string]string, error)
  2610  ```
  2611  ParseUrl 解析 URL,返回其组成部分. component为需要返回的组成; -1: all; 1: scheme; 2: host; 4:
  2612  port; 8: user; 16: pass; 32: path; 64: query; 128: fragment .
  2613  
  2614  #### func (*LkkString) Quotemeta
  2615  
  2616  ```go
  2617  func (ks *LkkString) Quotemeta(str string) string
  2618  ```
  2619  Quotemeta 转义元字符集,包括 . \ + * ? [ ^ ] ( $ ).
  2620  
  2621  #### func (*LkkString) Random
  2622  
  2623  ```go
  2624  func (ks *LkkString) Random(length uint8, rtype LkkRandString) string
  2625  ```
  2626  Random 生成随机字符串. length为长度,rtype为枚举: RAND_STRING_ALPHA 字母; RAND_STRING_NUMERIC
  2627  数值; RAND_STRING_ALPHANUM 字母+数值; RAND_STRING_SPECIAL 字母+数值+特殊字符;
  2628  RAND_STRING_CHINESE 仅中文.
  2629  
  2630  #### func (*LkkString) RawurlDecode
  2631  
  2632  ```go
  2633  func (ks *LkkString) RawurlDecode(str string) (string, error)
  2634  ```
  2635  RawurlDecode 对已编码的 URL 字符串进行解码.
  2636  
  2637  #### func (*LkkString) RawurlEncode
  2638  
  2639  ```go
  2640  func (ks *LkkString) RawurlEncode(str string) string
  2641  ```
  2642  RawurlEncode 按照 RFC 3986 对 URL 进行编码.
  2643  
  2644  #### func (*LkkString) RemoveAfter
  2645  
  2646  ```go
  2647  func (ks *LkkString) RemoveAfter(str, after string, include bool) string
  2648  ```
  2649  RemoveAfter 移除after之后的字符串.include为是否移除包括after本身.
  2650  
  2651  #### func (*LkkString) RemoveBefore
  2652  
  2653  ```go
  2654  func (ks *LkkString) RemoveBefore(str, before string, include bool) string
  2655  ```
  2656  RemoveBefore 移除before之前的字符串.include为是否移除包括before本身.
  2657  
  2658  #### func (*LkkString) RemoveSpace
  2659  
  2660  ```go
  2661  func (ks *LkkString) RemoveSpace(str string, all bool) string
  2662  ```
  2663  RemoveSpace 移除字符串中的空白字符. all为true时移除全部空白,为false时只替换连续的空白字符为一个空格.
  2664  
  2665  #### func (*LkkString) Reverse
  2666  
  2667  ```go
  2668  func (ks *LkkString) Reverse(str string) string
  2669  ```
  2670  Reverse 反转字符串.
  2671  
  2672  #### func (*LkkString) Rtrim
  2673  
  2674  ```go
  2675  func (ks *LkkString) Rtrim(str string, characterMask ...string) string
  2676  ```
  2677  Rtrim 删除字符串末端的空白字符(或者其他字符).
  2678  
  2679  #### func (*LkkString) SBC2DBC
  2680  
  2681  ```go
  2682  func (ks *LkkString) SBC2DBC(s string) string
  2683  ```
  2684  SBC2DBC 全角转半角.
  2685  
  2686  #### func (*LkkString) ShaX
  2687  
  2688  ```go
  2689  func (ks *LkkString) ShaX(str string, x uint16) string
  2690  ```
  2691  ShaX 计算字符串的 shaX 散列值,x为1/256/512 .
  2692  
  2693  #### func (*LkkString) Shuffle
  2694  
  2695  ```go
  2696  func (ks *LkkString) Shuffle(str string) string
  2697  ```
  2698  Shuffle 随机打乱字符串.
  2699  
  2700  #### func (*LkkString) SimilarText
  2701  
  2702  ```go
  2703  func (ks *LkkString) SimilarText(first, second string, percent *float64) int
  2704  ```
  2705  SimilarText 计算两个字符串的相似度,返回在两个字符串中匹配字符的数目;percent为相似程度百分数.
  2706  
  2707  #### func (*LkkString) StartsWith
  2708  
  2709  ```go
  2710  func (ks *LkkString) StartsWith(str, substr string) bool
  2711  ```
  2712  StartsWith 字符串str是否以substr开头.
  2713  
  2714  #### func (*LkkString) StripTags
  2715  
  2716  ```go
  2717  func (ks *LkkString) StripTags(str string) string
  2718  ```
  2719  StripTags 过滤html和php标签.
  2720  
  2721  #### func (*LkkString) Stripos
  2722  
  2723  ```go
  2724  func (ks *LkkString) Stripos(haystack, needle string, offset int) int
  2725  ```
  2726  Stripos 查找字符串首次出现的位置(不区分大小写),找不到时返回-1.
  2727  haystack在该字符串中进行查找,needle要查找的字符串,offset起始位置.
  2728  
  2729  #### func (*LkkString) Stripslashes
  2730  
  2731  ```go
  2732  func (ks *LkkString) Stripslashes(str string) string
  2733  ```
  2734  Stripslashes 反引用一个引用字符串.
  2735  
  2736  #### func (*LkkString) Strlen
  2737  
  2738  ```go
  2739  func (ks *LkkString) Strlen(str string) int
  2740  ```
  2741  Strlen 获取字符串长度.
  2742  
  2743  #### func (*LkkString) Strpad
  2744  
  2745  ```go
  2746  func (ks *LkkString) Strpad(str string, fill string, max int, ptype LkkPadType) string
  2747  ```
  2748  Strpad 使用fill填充str字符串到指定长度max. ptype为填充类型,枚举值(PAD_LEFT,PAD_RIGHT,PAD_BOTH).
  2749  
  2750  #### func (*LkkString) StrpadBoth
  2751  
  2752  ```go
  2753  func (ks *LkkString) StrpadBoth(str string, fill string, max int) string
  2754  ```
  2755  StrpadBoth 字符串两侧填充,请参考Strpad.
  2756  
  2757  #### func (*LkkString) StrpadLeft
  2758  
  2759  ```go
  2760  func (ks *LkkString) StrpadLeft(str string, fill string, max int) string
  2761  ```
  2762  StrpadLeft 字符串左侧填充,请参考Strpad.
  2763  
  2764  #### func (*LkkString) StrpadRight
  2765  
  2766  ```go
  2767  func (ks *LkkString) StrpadRight(str string, fill string, max int) string
  2768  ```
  2769  StrpadRight 字符串右侧填充,请参考Strpad.
  2770  
  2771  #### func (*LkkString) Strpos
  2772  
  2773  ```go
  2774  func (ks *LkkString) Strpos(haystack, needle string, offset int) int
  2775  ```
  2776  Strpos 查找字符串首次出现的位置,找不到时返回-1. haystack在该字符串中进行查找,needle要查找的字符串,offset起始位置.
  2777  
  2778  #### func (*LkkString) Strripos
  2779  
  2780  ```go
  2781  func (ks *LkkString) Strripos(haystack, needle string, offset int) int
  2782  ```
  2783  Strripos 查找指定字符串在目标字符串中最后一次出现的位置(不区分大小写).
  2784  
  2785  #### func (*LkkString) Strrpos
  2786  
  2787  ```go
  2788  func (ks *LkkString) Strrpos(haystack, needle string, offset int) int
  2789  ```
  2790  Strrpos 查找指定字符串在目标字符串中最后一次出现的位置.
  2791  
  2792  #### func (*LkkString) Substr
  2793  
  2794  ```go
  2795  func (ks *LkkString) Substr(str string, start int, length ...int) string
  2796  ```
  2797  Substr 截取字符串str的子串. start 为起始位置.若值是负数,返回的结果将从 str 结尾处向前数第 abs(start) 个字符开始.
  2798  length 为截取的长度.若值时负数, str 末尾处的 abs(length) 个字符将会被省略. start/length的绝对值必须<=原字符串长度.
  2799  
  2800  #### func (*LkkString) SubstrCount
  2801  
  2802  ```go
  2803  func (ks *LkkString) SubstrCount(str, substr string) int
  2804  ```
  2805  SubstrCount 计算字符串出现的次数.
  2806  
  2807  #### func (*LkkString) ToCamelCase
  2808  
  2809  ```go
  2810  func (ks *LkkString) ToCamelCase(str string) string
  2811  ```
  2812  ToCamelCase 转为驼峰写法. 去掉包括下划线"_"和横杠"-".
  2813  
  2814  #### func (*LkkString) ToKebabCase
  2815  
  2816  ```go
  2817  func (ks *LkkString) ToKebabCase(str string) string
  2818  ```
  2819  ToSnakeCase 转为串形写法. 使用横杠"-"连接.
  2820  
  2821  #### func (*LkkString) ToSnakeCase
  2822  
  2823  ```go
  2824  func (ks *LkkString) ToSnakeCase(str string) string
  2825  ```
  2826  ToSnakeCase 转为蛇形写法. 使用下划线"_"连接.
  2827  
  2828  #### func (*LkkString) Trim
  2829  
  2830  ```go
  2831  func (ks *LkkString) Trim(str string, characterMask ...string) string
  2832  ```
  2833  Trim 去除字符串首尾处的空白字符(或者其他字符).
  2834  
  2835  #### func (*LkkString) Ucfirst
  2836  
  2837  ```go
  2838  func (ks *LkkString) Ucfirst(str string) string
  2839  ```
  2840  Ucfirst 将字符串的第一个字符转换为大写.
  2841  
  2842  #### func (*LkkString) Ucwords
  2843  
  2844  ```go
  2845  func (ks *LkkString) Ucwords(str string) string
  2846  ```
  2847  Ucwords 将字符串中每个词的首字母转换为大写.
  2848  
  2849  #### func (*LkkString) Uniqid
  2850  
  2851  ```go
  2852  func (ks *LkkString) Uniqid(prefix string) string
  2853  ```
  2854  Uniqid 获取一个带前缀、基于当前时间微秒数的唯一ID.
  2855  
  2856  #### func (*LkkString) UrlDecode
  2857  
  2858  ```go
  2859  func (ks *LkkString) UrlDecode(str string) (string, error)
  2860  ```
  2861  UrlDecode 解码已编码的 URL 字符串.
  2862  
  2863  #### func (*LkkString) UrlEncode
  2864  
  2865  ```go
  2866  func (ks *LkkString) UrlEncode(str string) string
  2867  ```
  2868  UrlEncode 编码 URL 字符串.
  2869  
  2870  #### func (*LkkString) Utf8ToBig5
  2871  
  2872  ```go
  2873  func (ks *LkkString) Utf8ToBig5(s []byte) ([]byte, error)
  2874  ```
  2875  Utf8ToBig5 UTF-8转BIG5编码.
  2876  
  2877  #### func (*LkkString) Utf8ToGbk
  2878  
  2879  ```go
  2880  func (ks *LkkString) Utf8ToGbk(s []byte) ([]byte, error)
  2881  ```
  2882  Utf8ToGbk UTF-8转GBK编码.
  2883  
  2884  #### func (*LkkString) VersionCompare
  2885  
  2886  ```go
  2887  func (ks *LkkString) VersionCompare(version1, version2, operator string) bool
  2888  ```
  2889  VersionCompare 对比两个版本号字符串. operator允许的操作符有: <, lt, <=, le, >, gt, >=, ge, ==, =,
  2890  eq, !=, <>, ne . 特定的版本字符串,将会用以下顺序处理: 未找到的任意字符串 < dev < alpha = a < beta = b < RC
  2891  = rc < # < pl = p 用法: VersionCompare("1.2.3-alpha", "1.2.3RC7", '>=') ;
  2892  VersionCompare("1.2.3-beta", "1.2.3pl", 'lt') ; VersionCompare("1.1_dev",
  2893  "1.2any", 'eq') .
  2894  
  2895  #### type LkkTime
  2896  
  2897  ```go
  2898  type LkkTime byte
  2899  ```
  2900  
  2901  LkkTime is the receiver of time utilities
  2902  
  2903  #### func (*LkkTime) CheckDate
  2904  
  2905  ```go
  2906  func (kt *LkkTime) CheckDate(month, day, year int) bool
  2907  ```
  2908  CheckDate 检查是否正常的日期.
  2909  
  2910  #### func (*LkkTime) Date
  2911  
  2912  ```go
  2913  func (kt *LkkTime) Date(format string, ts ...interface{}) string
  2914  ```
  2915  Date 格式化时间. format 格式,如"Y-m-d H:i:s". ts为int/int64类型时间戳或time.Time类型.
  2916  
  2917  #### func (*LkkTime) Day
  2918  
  2919  ```go
  2920  func (kt *LkkTime) Day(t ...time.Time) int
  2921  ```
  2922  Day 获取日份.
  2923  
  2924  #### func (*LkkTime) GetMonthDays
  2925  
  2926  ```go
  2927  func (kt *LkkTime) GetMonthDays(month int, years ...int) int
  2928  ```
  2929  GetMonthDays 获取指定月份的天数.years年份,可选,默认当前年份.
  2930  
  2931  #### func (*LkkTime) Hour
  2932  
  2933  ```go
  2934  func (kt *LkkTime) Hour(t ...time.Time) int
  2935  ```
  2936  Hour 获取小时.
  2937  
  2938  #### func (*LkkTime) IsDate2time
  2939  
  2940  ```go
  2941  func (kt *LkkTime) IsDate2time(str string) (bool, int64)
  2942  ```
  2943  IsDate2time 检查字符串是否日期格式,并转换为时间戳.注意,时间戳可能为负数(小于1970年时). 匹配如:
  2944  
  2945      0000
  2946      0000-00
  2947      0000/00
  2948      0000-00-00
  2949      0000/00/00
  2950      0000-00-00 00
  2951      0000/00/00 00
  2952      0000-00-00 00:00
  2953      0000/00/00 00:00
  2954      0000-00-00 00:00:00
  2955      0000/00/00 00:00:00
  2956  
  2957  等日期格式.
  2958  
  2959  #### func (*LkkTime) MicroTime
  2960  
  2961  ```go
  2962  func (kt *LkkTime) MicroTime() int64
  2963  ```
  2964  MicroTime 获取当前Unix时间戳(微秒).
  2965  
  2966  #### func (*LkkTime) MilliTime
  2967  
  2968  ```go
  2969  func (kt *LkkTime) MilliTime() int64
  2970  ```
  2971  MilliTime 获取当前Unix时间戳(毫秒).
  2972  
  2973  #### func (*LkkTime) Minute
  2974  
  2975  ```go
  2976  func (kt *LkkTime) Minute(t ...time.Time) int
  2977  ```
  2978  Minute 获取分钟.
  2979  
  2980  #### func (*LkkTime) Month
  2981  
  2982  ```go
  2983  func (kt *LkkTime) Month(t ...time.Time) int
  2984  ```
  2985  Month 获取月份.
  2986  
  2987  #### func (*LkkTime) Second
  2988  
  2989  ```go
  2990  func (kt *LkkTime) Second(t ...time.Time) int
  2991  ```
  2992  Second 获取秒数.
  2993  
  2994  #### func (*LkkTime) ServiceStartime
  2995  
  2996  ```go
  2997  func (kt *LkkTime) ServiceStartime() int64
  2998  ```
  2999  ServiceStartime 获取当前服务启动时间戳,秒.
  3000  
  3001  #### func (*LkkTime) ServiceUptime
  3002  
  3003  ```go
  3004  func (kt *LkkTime) ServiceUptime() time.Duration
  3005  ```
  3006  ServiceUptime 获取当前服务运行时间,纳秒int64.
  3007  
  3008  #### func (*LkkTime) Sleep
  3009  
  3010  ```go
  3011  func (kt *LkkTime) Sleep(t int64)
  3012  ```
  3013  Sleep 延缓执行,秒.
  3014  
  3015  #### func (*LkkTime) Str2Timestamp
  3016  
  3017  ```go
  3018  func (kt *LkkTime) Str2Timestamp(str string, format ...string) (int64, error)
  3019  ```
  3020  Str2Timestamp 将字符串转换为时间戳,秒. str 为要转换的字符串; format 为该字符串的格式,默认为"2006-01-02
  3021  15:04:05" .
  3022  
  3023  #### func (*LkkTime) Str2Timestruct
  3024  
  3025  ```go
  3026  func (kt *LkkTime) Str2Timestruct(str string, format ...string) (time.Time, error)
  3027  ```
  3028  Str2Time 将字符串转换为时间结构. str 为要转换的字符串; format 为该字符串的格式,默认为"2006-01-02 15:04:05" .
  3029  
  3030  #### func (*LkkTime) Time
  3031  
  3032  ```go
  3033  func (kt *LkkTime) Time() int64
  3034  ```
  3035  Time 获取当前Unix时间戳(秒).
  3036  
  3037  #### func (*LkkTime) Usleep
  3038  
  3039  ```go
  3040  func (kt *LkkTime) Usleep(t int64)
  3041  ```
  3042  Usleep 以指定的微秒数延迟执行.
  3043  
  3044  #### func (*LkkTime) Year
  3045  
  3046  ```go
  3047  func (kt *LkkTime) Year(t ...time.Time) int
  3048  ```
  3049  Year 获取年份.
  3050  
  3051  #### type SystemInfo
  3052  
  3053  ```go
  3054  type SystemInfo struct {
  3055  	ServerName   string  `json:"server_name"`    //服务器名称
  3056  	Runtime      int64   `json:"run_time"`       //服务运行时间,纳秒
  3057  	GoroutineNum int     `json:"goroutine_num"`  //goroutine数量
  3058  	CpuNum       int     `json:"cpu_num"`        //cpu核数
  3059  	CpuUser      float64 `json:"cpu_user"`       //cpu用户态比率
  3060  	CpuFree      float64 `json:"cpu_free"`       //cpu空闲比率
  3061  	DiskUsed     uint64  `json:"disk_used"`      //已用磁盘空间,字节数
  3062  	DiskFree     uint64  `json:"disk_free"`      //可用磁盘空间,字节数
  3063  	DiskTotal    uint64  `json:"disk_total"`     //总磁盘空间,字节数
  3064  	MemUsed      uint64  `json:"mem_used"`       //已用内存,字节数
  3065  	MemSys       uint64  `json:"mem_sys"`        //系统内存占用量,字节数
  3066  	MemFree      uint64  `json:"mem_free"`       //剩余内存,字节数
  3067  	MemTotal     uint64  `json:"mem_total"`      //总内存,字节数
  3068  	AllocGolang  uint64  `json:"alloc_golang"`   //golang内存使用量,字节数
  3069  	AllocTotal   uint64  `json:"alloc_total"`    //总分配的内存,字节数
  3070  	Lookups      uint64  `json:"lookups"`        //指针查找次数
  3071  	Mallocs      uint64  `json:"mallocs"`        //内存分配次数
  3072  	Frees        uint64  `json:"frees"`          //内存释放次数
  3073  	LastGCTime   uint64  `json:"last_gc_time"`   //上次GC时间,纳秒
  3074  	NextGC       uint64  `json:"next_gc"`        //下次GC内存回收量,字节数
  3075  	PauseTotalNs uint64  `json:"pause_total_ns"` //GC暂停时间总量,纳秒
  3076  	PauseNs      uint64  `json:"pause_ns"`       //上次GC暂停时间,纳秒
  3077  }
  3078  ```
  3079  
  3080  SystemInfo 系统信息