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