{"id":34236506,"url":"https://github.com/up-zero/gotool","last_synced_at":"2026-03-11T09:04:50.523Z","repository":{"id":186332225,"uuid":"675000816","full_name":"up-zero/gotool","owner":"up-zero","description":"gotool 轻量级的Golang工具库（无第三方库依赖）","archived":false,"fork":false,"pushed_at":"2026-02-26T14:14:12.000Z","size":672,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-26T20:29:14.650Z","etag":null,"topics":["go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/up-zero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-08-05T12:51:12.000Z","updated_at":"2026-02-26T14:14:16.000Z","dependencies_parsed_at":"2024-04-28T08:30:24.742Z","dependency_job_id":"191adc63-d42b-4d94-84f9-adeb8abf1641","html_url":"https://github.com/up-zero/gotool","commit_stats":null,"previous_names":["up-zero/gotool"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/up-zero/gotool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/up-zero%2Fgotool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/up-zero%2Fgotool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/up-zero%2Fgotool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/up-zero%2Fgotool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/up-zero","download_url":"https://codeload.github.com/up-zero/gotool/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/up-zero%2Fgotool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30376787,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T06:09:32.197Z","status":"ssl_error","status_checked_at":"2026-03-11T06:09:17.086Z","response_time":84,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang"],"created_at":"2025-12-16T02:47:09.966Z","updated_at":"2026-03-11T09:04:50.517Z","avatar_url":"https://github.com/up-zero.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n    \u003cimg width=\"300\" src=\"./assets/logo.png\" alt=\"\"\u003e\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n   \u003ca href=\"https://github.com/up-zero/gotool/fork\" target=\"blank\"\u003e\n      \u003cimg src=\"https://img.shields.io/github/forks/up-zero/gotool?style=for-the-badge\" alt=\"Gotool forks\"/\u003e\n   \u003c/a\u003e\n   \u003ca href=\"https://github.com/up-zero/gotool/stargazers\" target=\"blank\"\u003e\n      \u003cimg src=\"https://img.shields.io/github/stars/up-zero/gotool?style=for-the-badge\" alt=\"Gotool stars\"/\u003e\n   \u003c/a\u003e\n   \u003ca href=\"https://github.com/up-zero/gotool/pulls\" target=\"blank\"\u003e\n      \u003cimg src=\"https://img.shields.io/github/issues-pr/up-zero/gotool?style=for-the-badge\" alt=\"Gotool pull-requests\"/\u003e\n   \u003c/a\u003e\n\u003c/p\u003e\n\n一个轻量级的Go语言工具库，提倡的核心理念为：基于Golang标准库、无第三方依赖。\n\n## 安装\n\n```shell\ngo get -u github.com/up-zero/gotool\n```\n\n## 快速开始\n\n例如 `Md5()` 方法，使用方式如下所示，其它方法参考功能列表及其测试案例。\n\n```go\npackage main\n\nimport \"github.com/up-zero/gotool/cryptoutil\"\nimport \"log\"\n\nfunc main() {\n\tdata, err := cryptoutil.Md5(\"123456\") // e10adc3949ba59abbe56e057f20f883e\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\tlog.Println(data)\n}\n```\n\n## 方法列表\n\n### 文件（fileutil）\n\n+ **FileCopy** 文件拷贝\n+ **FileMove** 文件移动\n+ **DirCopy** 绝对目录文件拷贝\n+ **CurrentDirCount** 当前文件夹下(不迭代子文件夹)文件或文件夹的个数\n+ **MkParentDir** 创建父级文件夹\n+ **FileCount** 获取指定目录下的文件个数\n+ **FileMainName** 获取指定路径的文件名\n+ **FileSave** 保存文件\n+ **FileSync** 文件同步\n+ **FileRead** 读文件（结构体）\n+ **FileReadLine** 按行流式读取文件\n+ **Zip** 文件夹压缩\n+ **ZipWithNotify** 带通知的文件夹压缩\n+ **Unzip** 文件解压\n+ **UnzipWithNotify** 带通知的文件解压\n+ **FileSize** 获取文件大小\n+ **Exist** 判断文件或目录是否存在\n+ **IsDir** 判断是否是目录\n+ **IsFile** 判断是否是文件\n\n### 加解密（cryptoutil）\n\n+ **Md5** 获取md5值\n+ **Md5Iterations** 迭代多次求MD5\n+ **Md5File** 获取文件的MD5\n+ **HmacSHA256** 计算 SHA256\n+ **HmacSHA384** 计算 HmacSHA384\n+ **HmacSHA512** 计算 HmacSHA512\n+ **Base64Encode** base64 编码\n+ **Base64Decode** base64 解码\n+ **JWTGenerate** 生成JWT\n+ **JWTParse** 解析JWT\n+ **Sha1** 获取SHA1值\n+ **Sha256** 获取SHA256值\n+ **Sha512** 获取SHA512值\n+ **Sha1File** 获取文件SHA1值\n+ **Sha256File** 获取文件SHA256值\n+ **Sha512File** 获取文件SHA512值\n+ **AesCbcEncrypt** AES CBC 加密\n+ **AesCbcDecrypt** AES CBC 解密\n+ **AesGcmEncrypt** AES GCM 加密\n+ **AesGcmDecrypt** AES GCM 解密\n+ **RsaEncrypt** RSA 公钥加密\n+ **RsaDecrypt** RSA 私钥解密\n+ **RsaGenerateKey** 生成RSA密钥对，返回PEM格式的私钥和公钥字符串\n+ **RsaEncryptFile** 使用 RSA 公钥加密文件\n+ **RsaDecryptFile** 使用 RSA 私钥解密文件\n+ **GenSelfSignedCert** 生成自签名证书和私钥\n\n### 类型转换（convertutil）\n\n+ **StrToInt** 字符串转换为int\n+ **StrToInt8** 字符串转换为int8\n+ **StrToInt16** 字符串转换为int16\n+ **StrToInt32** 字符串转换为int32\n+ **StrToInt64** 字符串转换为int64\n+ **StrToUint** 字符串转换为uint\n+ **StrToUint8** 字符串转换为uint8\n+ **StrToUint16** 字符串转换为uint16\n+ **StrToUint32** 字符串转换为uint32\n+ **StrToUint64** 字符串转换为uint64\n+ **StrToFloat32** 字符串转换为float32\n+ **StrToFloat64** 字符串转换为float64\n+ **Int64ToStr** int64转换为字符串\n+ **Uint64ToStr** uint64转换为字符串\n+ **ToStr** 将任意类型的值转换为字符串\n+ **Float64ToStr** float64转换为字符串\n+ **Int64ToHex** int64转换为十六进制字符串\n+ **HexToInt64** 十六进制字符串转换为int64\n+ **CopyProperties** 复制结构体的属性\n+ **DigitToChinese** 数字逐位转汉字\n+ **IntegerToChinese** 整数转中文读法\n\n### 随机数（randomutil）\n\n+ **String** 随机字符串\n+ **Digits** 随机数字\n+ **Letters** 随机字母\n+ **Alphanumeric** 随机字母数字\n+ **IntRange** 指定范围内的随机数 [最小值, 最大值)\n+ **Bool** 随机布尔值\n+ **Choice** 从切片随机选一个元素\n\n### 数学（mathutil）\n\n+ **Abs** 绝对值\n+ **Min** 最小值\n+ **Max** 最大值\n+ **Sum** 求和\n+ **Average** 平均值\n+ **ConvexHull** 计算凸包\n+ **SimplifyPath** 简化路径\n+ **OffsetPolygon** 多边形偏移 (内缩/外扩)\n+ **TranslatePolygon** 多边形平移，按指定向量移动多边形\n+ **PolygonArea** 计算多边形的面积\n+ **GetAABB** 计算点集的轴对齐最小外接矩\n+ **HammingDistance** 汉明距离\n\n### 媒体（mediautil）\n\n+ **ReadWavHeader** 从文件中读取 WAV 头部\n+ **ParseWavHeader** 从字节切片中解析 WAV 头部\n+ **WavHeader_GetDuration** 根据头部信息计算音频时长\n+ **WriteWav** 将 PCM 数据封装为 WAV 格式写入 io.Writer\n+ **SaveWav** 将 PCM 数据保存为本地 WAV 文件\n+ **Float32ToPcmBytes** 将标准浮点音频数据转换为指定位深的 PCM 字节流\n+ **Float32ToWavBytes** 将标准浮点音频数据转换为完整的 WAV 文件字节流\n+ **TextToChinese** 中文文本口语化转换\n+ **PcmBytesToFloat32** PCM 字节流转 float32 数组\n+ **ReformatWavBytes** WAV 字节流格式转换\n+ **PreEmphasis** 预加重滤波器\n+ **HammingWindow** 汉明窗\n+ **HannWindow** 汉宁窗\n+ **FFT** 快速傅里叶变换\n+ **MelFilters** 生成 Mel 滤波器组权重矩阵\n+ **ApplyCMVN** 倒谱均值方差归一化\n\n### 网络（netutil）\n\n+ **SendMail** 发送邮件\n+ **Ipv4sLocal** 获取本地ipv4地址\n+ **ShouldBindJson** json入参绑定\n+ **ShouldBindQuery** query入参绑定\n+ **UrlBase** 获取URL路径的基础名称\n+ **HttpGet** http get 请求\n+ **HttpPost** http post 请求\n+ **HttpPut** http put 请求\n+ **HttpDelete** http delete 请求\n+ **HttpGetWithTimeout** 带超时时间的 http get 请求\n+ **HttpPostWithTimeout** 带超时时间的 http post 请求\n+ **HttpPutWithTimeout** 带超时时间的 http put 请求\n+ **HttpDeleteWithTimeout** 带超时时间的 http delete 请求\n+ **ParseResponse** 解析响应结果\n+ **FileDownload** 文件下载\n+ **FileDownloadWithNotify** 带通知的文件下载\n+ **FileDownloadWithProgress** 带进度的文件下载\n\n### 系统（sysutil）\n\n+ **ExecShell** 运行shell命令或脚本\n+ **ExecCommand** 运行命令\n+ **ExecShellWithNotify** 带通知的运行shell命令或脚本\n+ **ExecCommandWithNotify** 带通知的运行命令\n+ **ExecCommandWithOutput** 执行命令并返回合并后的标准输出和标准错误\n+ **ExecCommandWithStream** 执行命令并对 stdout 和 stderr 的每一行实时调用回调函数\n+ **PsByName** 根据程序名查询进程列表\n+ **CPUTemperatures**  获取CPU温度\n+ **SysUptime**  系统启动时间\n\n### 日期\u0026时间（timeutil）\n\n+ **TransformLayout** 时间字符串格式转换\n+ **FormatRFC3339** 将 RFC3339 格式转换为指定格式\n+ **FormatRFC1123** 将 RFC1123 格式转换为指定格式\n\n### 唯一ID（idutil）\n\n+ **UUID** uuid\n+ **UUIDGenerate** 生成UUID\n+ **SignalSnowflake** 单节点的雪花码\n+ **NewObjectID** 生成一个新的 ObjectID\n\n### 切片（sliceutil）\n\n+ **Unique** 切片去重，求并集\n+ **Contains** 切片是否包含某个值\n+ **Join** 切片拼接成字符串\n+ **Concat** 切片拼接\n+ **Intersect** 求多个切片的交集，元素存在时会先去重\n+ **Filter** 切片过滤\n+ **Map** 切片类型转换\n+ **GroupBy** 将切片按指定的 Key 进行分组\n+ **Chunk** 将切片按指定大小切分为多个小切片\n+ **Difference** 求差集 (s1 - s2)，返回在 s1 中但不在 s2 中的元素\n+ **Shuffle** 切片洗牌\n\n### 图片（imageutil）\n\n+ **Open** 打开图片\n+ **Save** 保存图片\n+ **Compression** 图片压缩\n+ **Size** 图片尺寸\n+ **GenerateCaptcha** 验证码图片生成\n+ **Crop** 图片裁剪\n+ **CropFile** 图片文件裁剪\n+ **Resize** 图片缩放\n+ **ResizeFile** 图片文件缩放\n+ **Rotate** 旋转图片\n+ **RotateFile** 旋转图片文件\n+ **Flip** 翻转图片\n+ **FlipFile** 翻转图片文件\n+ **Overlay** 图片叠加\n+ **OverlayFile** 图片文件叠加\n+ **Grayscale** 图片灰度化\n+ **GrayscaleFile** 图片文件灰度化\n+ **GaussianBlur** 图片高斯模糊\n+ **GaussianBlurFile** 图片文件高斯模糊\n+ **AdjustBrightness** 图片亮度调整\n+ **AdjustBrightnessFile** 图片文件亮度调整\n+ **Invert** 图片反转颜色\n+ **InvertFile** 图片文件反转颜色\n+ **Binarize** 图片二值化\n+ **BinarizeFile** 图片文件二值化\n+ **OtsuThreshold** 基于大津法计算推荐阈值\n+ **MedianBlur** 图片中值滤波\n+ **MedianBlurFile** 图片文件中值滤波\n+ **Sobel** 索贝尔边缘检测\n+ **SobelFile** 图片文件索贝尔边缘检测\n+ **NewRectKernel** 创建矩形核\n+ **NewCrossKernel** 创建十字形核\n+ **Erode** 图片腐蚀\n+ **ErodeFile** 图片文件腐蚀\n+ **Dilate** 图片膨胀\n+ **DilateFile** 图片文件膨胀\n+ **MorphologyOpen** 开运算\n+ **MorphologyOpenFile** 对图片文件进行开运算\n+ **MorphologyClose** 闭运算\n+ **MorphologyCloseFile** 对图片文件进行闭运算\n+ **EqualizeHist** 直方图均衡化\n+ **EqualizeHistFile** 图片文件直方图均衡化\n+ **DrawFilledCircle** 绘制填充的圆形\n+ **DrawThickLine** 绘制粗线\n+ **DrawLine** 绘制直线\n+ **DrawRectOutline** 绘制矩形边框\n+ **DrawFilledRect** 矩形填充\n+ **DrawThickRectOutline** 绘制粗矩形边框\n+ **DrawPolygonOutline** 绘制多边形边框\n+ **DrawThickPolygonOutline** 绘制粗多边形边框\n+ **DrawFilledPolygon** 多边形填充\n+ **ConvexHull** 计算凸包\n+ **SimplifyPath** 简化路径\n+ **OffsetPolygon** 多边形偏移 (内缩/外扩)\n+ **GenerateSolid** 生成指定宽高的纯色背景图片\n+ **FindBlobs** 查找 Mask 图片的连通区域\n+ **AHash** 平均哈希\n+ **DHash** 差异哈希\n+ **PHash** 感知哈希\n+ **ToWritable** 将 image.Image 转换为可写的 draw.Image\n\n### 条件判断（conditionutil）\n\n+ **If** 三元运算符\n+ **IfLazy** 延迟执行的三元运算\n+ **IsZero** 判断一个值是否为零值\n\n### 流（streamutil）\n\n+ **NewStream** 初始化 Stream\n+ **Stream_Filter** 数据过滤\n+ **Stream_Map** 数据处理\n+ **Stream_Extreme** 返回流中的极值\n+ **Stream_Max** 数据最大值\n+ **Stream_Min** 数据最小值\n+ **Stream_ToSlice** 转换为切片\n+ **StreamMap** 数据处理与转换\n\n### 结构体（structutil）\n\n+ **SetDefaults** 设置结构体默认值\n+ **NewWithDefaults** 初始化带有默认值的结构体\n+ **ToMap** 将结构体转换为 map[string]any\n\n### 字符串（stringutil）\n\n+ **Reverse** 字符串反转\n+ **TakeFirst** 截取字符串前 n 个 Unicode 字符（rune）\n+ **ContainsAny** 判断字符串 s 是否包含 substrs 中的任意一个子串\n+ **ContainsAll** 判断字符串 s 是否包含 substrs 中的所有子串\n+ **CamelToSnake** 将驼峰式字符串转换为下划线连接\n+ **SnakeToCamel** 将下划线连接的字符串转换为小驼峰式\n+ **SnakeToPascal** 将下划线连接的字符串转换为大驼峰式（PascalCase）\n+ **TrimFirstPrefix** 移除字符串中首个匹配的前缀\n+ **TrimFirstSuffix** 移除字符串中首个匹配的后缀\n+ **Ellipsis** 截取字符串，并在末尾添加省略号\n\n### 验证器（validator）\n\n+ **IsDigit** 判断字符串是否为数字\n+ **IsAlpha** 验证字符串是否为 Unicode 字符\n+ **IsAlphaStrict** 验证字符串是否为英文字符 a-z A-Z\n+ **IsAlphaNumeric** 验证字符串是否为 Unicode 字符或数字\n+ **IsIp** 检查字符串是否为有效的 IPv4 或 IPv6 地址\n+ **IsIpv4** 验证字符串是否为 IPv4 地址\n+ **IsIpv6** 验证字符串是否为 IPv6 地址\n+ **IsEmail** 判断字符串是否为有效的电子邮件地址\n+ **IsURL** 验证字符串是否为有效的 URL\n+ **ContainChinese** 判断字符串是否包含中文字符\n\n### 测试（testutil）\n\n+ **Equal** 断言两个值相等\n+ **EqualFloat** 断言两个值（浮点数或浮点数切片）在误差范围内相等\n+ **NotEqual** 断言两个值不相等\n\n### MAP工具（maputil）\n\n+ **NewConcurrentMap** 初始化并发 Map\n+ **ConcurrentMap_Set** 设置键值对（写操作）\n+ **ConcurrentMap_Get** 获取值（读操作）\n+ **ConcurrentMap_GetOrSet** 获取一个键的值（读操作），如果键不存在，则设置并返回新值（写操作）\n+ **ConcurrentMap_Delete** 删除键（写操作）\n+ **ConcurrentMap_GetAndDelete** 获取键的值并删除（写操作）\n+ **ConcurrentMap_Len** 获取 Map 中元素的数量（读操作）\n+ **ConcurrentMap_Clear** 清空 Map 中的所有元素（写操作）\n+ **ConcurrentMap_Range** 遍历 Map（读操作）\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fup-zero%2Fgotool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fup-zero%2Fgotool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fup-zero%2Fgotool/lists"}