github.com/PandaGoAdmin/utils@v0.0.0-20211208134815-d5461603a00f/README.md (about) 1 # utils 2 3 k`s golang helper/library/utils 4 golang 常用函数库/工具集,仅测试支持有限的64位系统. 5 总共450多个通用的方法,涵盖字符串、数组、文件、时间、加密以及类型转换等操作. 6 7 ### 测试支持 8 9 - GO版本 10 - 1.16.x 11 - 1.17.x 12 - OS系统 13 - ubuntu-latest 14 - macos-latest 15 - windows-latest 16 17 ### 依赖第三方库 18 19 - github.com/json-iterator/go 20 - github.com/StackExchange/wmi 21 22 ### 安装使用 23 24 安装 25 26 ```shell script 27 go get -u github.com/PandaGoAdmin/utils 28 ``` 29 30 引入 31 32 ```go 33 import "github.com/PandaGoAdmin/utils" 34 ``` 35 36 ### 函数接收器 37 38 - *KFile* 为文件操作,如 39 40 ```go 41 chk := KFile.IsExist(filename) 42 ``` 43 44 - *KStr* 为字符串操作,如 45 46 ```go 47 res := KStr.Trim(" hello world ") 48 ``` 49 50 - *KNum* 为数值操作,如 51 52 ```go 53 res := KNum.NumberFormat(123.4567890, 3, ".", "") 54 ``` 55 56 - *KArr* 为数组(切片/字典)操作,如 57 58 ```go 59 mp := map[string]string{ 60 "a": "aa", 61 "b": "bb", 62 } 63 chk := KArr.InArray("bb", mp) 64 ``` 65 66 - *KTime* 为时间操作,如 67 68 ```go 69 res, err := KTime.Str2Timestamp("2019-07-11 10:11:23") 70 ``` 71 72 - *KConv* 为类型转换操作,如 73 74 ```go 75 res := KConv.ToStr(false) 76 ``` 77 78 - *KOS* 为系统和网络操作,如 79 80 ```go 81 res, err := KOS.LocalIP() 82 ``` 83 84 - *KEncr* 为加密操作,如 85 86 ```go 87 res, err := KEncr.PasswordHash([]byte("123456")) 88 ``` 89 90 - *KDbug* 为调试操作,如 91 92 ```go 93 KDbug.DumpPrint(1.2) 94 ``` 95 96 具体函数请查看[godoc](https://pkg.go.dev/github.com/PandaGoAdmin/utils),更多示例请参考*_test.go文件. 97 98 ### 测试 99 100 ```shell 101 #使用go mod 102 go mod tidy 103 go mod vendor 104 105 #单元测试 106 go test -race 107 108 #压测 109 time go test -bench=. -run=none 110 time go test -v -bench=. -cpu=4 -benchtime="10s" -timeout="15s" -benchmem 111 112 #代码覆盖率 113 go test -cover #概览 114 115 go test -coverprofile=coverage.out #生成统计信息 116 go test -v -covermode=count -coverprofile=coverage.out 117 go tool cover -func=coverage.out #查看统计信息 118 go tool cover -html=coverage.out #将统计信息转换为html 119 120 #性能分析 121 time go test -timeout 30m -bench=. -benchmem -memprofile memprofile.out -cpuprofile profile.out 122 go tool pprof profile.out 123 go tool pprof -http=192.168.1.2:8081 /usr/bin/dot profile.out 124 ``` 125 126 ### 更新日志 127 128 详见[[Changelog]](/docs/changelog.md) 129 130 ### 鸣谢 131 132 感谢[JetBrains](https://www.jetbrains.com/?from=kakuilan/kgo)的赞助. 133  134