{"id":34842277,"url":"https://github.com/serialt/gopkg","last_synced_at":"2026-05-25T10:02:27.010Z","repository":{"id":57644371,"uuid":"350564919","full_name":"serialt/gopkg","owner":"serialt","description":"Go 函数库","archived":false,"fork":false,"pushed_at":"2025-03-12T23:55:46.000Z","size":209,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-27T02:20:27.008Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serialt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2021-03-23T03:15:40.000Z","updated_at":"2024-12-14T07:31:55.000Z","dependencies_parsed_at":"2024-06-20T15:32:10.251Z","dependency_job_id":"ebf63edb-3717-4955-9dd4-1906c4eaa7c2","html_url":"https://github.com/serialt/gopkg","commit_stats":null,"previous_names":["serialt/go-pkg"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/serialt/gopkg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fgopkg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fgopkg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fgopkg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fgopkg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serialt","download_url":"https://codeload.github.com/serialt/gopkg/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fgopkg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33469418,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-25T06:32:55.349Z","status":"ssl_error","status_checked_at":"2026-05-25T06:32:35.322Z","response_time":57,"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":[],"created_at":"2025-12-25T17:13:04.520Z","updated_at":"2026-05-25T10:02:26.990Z","avatar_url":"https://github.com/serialt.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## go函数库\n\n### 使用方法\n\n```\n    go get -u  github.com/serialt/gopkg\n```\n\n\n\n### 函数清单\n\n`shell`\n\n| 函数名                      | 说明                            | 备注 |\n| --------------------------- | ------------------------------- | ---- |\n| FindCommandPath,Where       | 查找命令的路径                  |      |\n| RunCmd                      | 获取标准正确输出                |      |\n| RunCommandWithTimeout       | 带超时控制的执行shell命令       |      |\n| FindUser                    | 查找操作系统上的用户            |      |\n| GetLoginUser,GetCurrentUser | 获取当前登录的用户              |      |\n| UserHomeDir                 | 获取当前用户家目录              |      |\n| UserCacheDir                | 当前用户缓存目录，$HOME/.cache  |      |\n| UserConfigDir               | 当前用户配置目录，$HOME/.config |      |\n| Hostname                    | 获取主机名                      |      |\n| IsMSys                      | 判断是否是msys(MINGW64)         |      |\n| CurrentShell                | 获取操作系统的shell             |      |\n| HasShellEnv                 | 判断操作系统是否有此shell       |      |\n| IsShellSpecialVar           | 判断是否是shell的变量字符       |      |\n| Workdir                     | 获取workspace                   |      |\n\n`string`\n\n| 函数名                      | **说明**                                        | **备注** |\n| --------------------------- | ----------------------------------------------- | -------- |\n| StringIsEmpty               | 判断字符串是否为空，是则返回true，否则返回false |          |\n| StringIsNotEmpty            | 判断字符串是否不为空                            |          |\n| StringConvert               | 去掉下划线并将下划线后的首字母大写              |          |\n| StringRandSeq               | 创建指定长度的随机字符串                        |          |\n| StringRandSeq16             | 创建长度为16的随机字符串                        |          |\n| StringAllLetter             | 判断字符串是否只由字母组成                      |          |\n| StringTrim                  | 去除字符串中的空格和换行符                      |          |\n| StringTrimN                 | 去除字符串中的换行符                            |          |\n| ToString                    | 将对象格式化成字符串                            |          |\n| StringSingleValue           | 将字符串内所有连续value替换为单个value          |          |\n| StringSingleSpace           | 将字符串内所有连续空格替换为单个空格            |          |\n| StringPrefixSupplementZero  | 当字符串长度不满足时，将字符串前几位补充0       |          |\n| SubString                   | 截取字符串                                      |          |\n| StringBuild，StringBuildSep | 拼接字符串                                      |          |\n| FilterPrefix                | 根据前缀过滤slice                               |          |\n| FindLongestStr              | 查询最长字符串                                  |          |\n| ArrayToString               | 数字切片变字符串                                |          |\n| StructToMap                 | 结构体转map                                     |          |\n\n`time`\n\n| 函数名           | **说明**         | **备注** |\n| ---------------- | ---------------- | -------- |\n| Timestamp2String | 时间戳转字符串   |          |\n| String2Timestamp | 字符串转时间戳   |          |\n| GetDate          | 返回系统当前时间 |          |\n| GetRunTime       | 获取当前系统环境 |          |\n\n`file`\n\n| 函数名             | **说明**                                                     | **备注** |\n| ------------------ | ------------------------------------------------------------ | -------- |\n| GetRootPath        | 获取项目路径                                                 |          |\n| DirExist，IsDir    | 判断目录否存在                                               |          |\n| Mode               | unix类系统获取文件的权限                                     |          |\n| FileExt，Suffix    | 获取文件的后缀, main.go 获取的后缀是.go                      |          |\n| Prefix             | 获取文件名前缀, /tmp/main.go 获取的文件前缀是main            |          |\n| CreateEmptyFile    | 创建空文件                                                   |          |\n| FileExists，IsFile | 文件是否存在                                                 |          |\n| IsAbsPath          | 是否是绝对路径                                               |          |\n| PathDir            | 获取路径的目录                                               |          |\n| Name               | 获取路径的文件名                                             |          |\n| DeleteFile         | 删除文件或目录                                               |          |\n| MkDir              | 创建文件夹,支持x/a/a  多层级                                 |          |\n| FilePathExists     | 判断路径是否存在                                             |          |\n| FileReadFirstLine  | 从文件中读取第一行并返回字符串数组                           |          |\n| FileReadPointLine  | 从文件中读取指定行并返回字符串数组                           |          |\n| FileReadLines      | 从文件中逐行读取并返回字符串数组                             |          |\n| FileParentPath     | 文件父路径                                                   |          |\n| ReadFile           | 读文件                                                       |          |\n| WriteFile          | 写文件                                                       |          |\n| WriteStringToFile  | 带权限位写文件                                               |          |\n| FileAppend         | 文件追加内容                                                 |          |\n| RecreateDir        | 创建目录                                                     |          |\n| GetFilepaths       | 获取目录里的所有文件                                         |          |\n| GetFiles           | 获取文件，返回文件路径和内容                                 |          |\n| FileLoopDirs       | 遍历目录下的所有子目录，即返回pathname下面的所有目录，目录为绝对路径 |          |\n| FileLoopOneDirs    | 遍历目录下的所有子目录，即返回pathname下面的所有目录，目录为相对路径 |          |\n| FileLoopFileNames  | 遍历文件夹及子文件夹下的所有文件名，即返回pathname目录下所有的文件，文件名为相对路径 |          |\n| FileMove           | 移动文件                                                     |          |\n| TrimSpace          | 去除空格                                                     |          |\n| FileCompressZip    | zip压缩文件                                                  |          |\n| FileDeCompressZip  | zip解压文件                                                  |          |\n| FileCompressTar    | tar压缩文件                                                  |          |\n| FileCopy           | 文件复制                                                     |          |\n| IsImageFile        | 判断是否是图片                                               |          |\n| IsZipFile          | 判断是否zip压缩文件                                          |          |\n| OSTempFile         | 创建临时文件                                                 |          |\n| TempFile           | 指定目录里创建临时文件                                       |          |\n| UserHomePath       | 用户家目录                                                   |          |\n| Mkdir              | 带权限创建目录                                               |          |\n| OpenFile           | 打开一个文件                                                 |          |\n| QuickOpenFile      | 快速打开一个文件                                             |          |\n| CreateFile         | 创建文件                                                     |          |\n| DeleteIfExist      | 删除文件                                                     |          |\n| Unzip              | 解压zip                                                      |          |\n\n`byte`\n\n| 函数名        | 说明             | 备注 |\n| ------------- | ---------------- | ---- |\n| GetBytes      | 获取接口字节数组 |      |\n| IntToBytes    | int转换成字节    |      |\n| BytesToInt    | 字节转换成int    |      |\n| Uint16ToBytes | uint16转换成字节 |      |\n| BytesToUint16 | 字节转换成uint16 |      |\n| Uint32ToBytes | uint32转换成字节 |      |\n| BytesToUint32 | 字节转换成uint32 |      |\n| Uint64ToBytes | uint64转换成字节 |      |\n| BytesToUint64 | 字节转换成uint64 |      |\n\n`env`\n\n| 函数名         | 说明                            | 备注 |\n| -------------- | ------------------------------- | ---- |\n| EnvGet         | 环境变量名称                    |      |\n| EnvGetD        | 环境变量为空时的默认值          |      |\n| EnvGetInt      | 获取环境变量 envName 的值       |      |\n| EnvGetIntD     | 环境变量为空时的默认值          |      |\n| EnvGetInt64    | 获取环境变量的值                |      |\n| EnvGetInt64D   | 环境变量为空时的默认值          |      |\n| EnvGetUint64   | 获取环境变量的值                |      |\n| EnvGetUint64D  | 获取环境变量的值                |      |\n| EnvGetFloat64  | 获取环境变量的值                |      |\n| EnvGetFloat64D | 获取环境变量的值                |      |\n| EnvGetBool     | 获取环境变量的值                |      |\n| Environ        | 获取所有的环境变量，返回map数据 |      |\n| IsAIX          | 判断操作系统类型                |      |\n| IsAndroid      | 判断操作系统类型                |      |\n| IsMac          | 判断操作系统类型                |      |\n| IsDarwin       | 判断操作系统类型                |      |\n| IsFreeBSD      | 判断操作系统类型                |      |\n| IsIOS          | 判断操作系统类型                |      |\n| IsLinux        | 判断操作系统类型                |      |\n| IsNetBSD       | 判断操作系统类型                |      |\n| IsOpenBSD      | 判断操作系统类型                |      |\n| IsPlan9        | 判断操作系统类型                |      |\n| IsWin          | 判断操作系统类型                |      |\n| IsWindows      | 判断操作系统类型                |      |\n| Is386          | 判断操作系统类型                |      |\n| IsAMD64        | 判断操作系统类型                |      |\n| IsRISCV64      | 判断操作系统类型                |      |\n\n`excelize`\n\n| 函数名          | 说明                    | 备注 |\n| --------------- | ----------------------- | ---- |\n| PasreExcel2List | 读取excel文件到二位切片 |      |\n| PasreList2Excel | 解析二位切片到excel文件 |      |\n\n`hash`\n\n| 函数名          | 说明 | 备注 |\n| --------------- | ---- | ---- |\n| HashMD5Bytes    |      |      |\n| HashMD5         |      |      |\n| HashMD516Bytes  |      |      |\n| HashMD516       |      |      |\n| HashSha1Bytes   |      |      |\n| HashSha1        |      |      |\n| HashSha224Bytes |      |      |\n| HashSha224      |      |      |\n| HashSha256Bytes |      |      |\n| HashSha256      |      |      |\n| HashSha384Bytes |      |      |\n| HashSha384      |      |      |\n| HashSha512Bytes |      |      |\n| HashSha512      |      |      |\n\n`ip`\n\n| 函数名          | 说明                                                         | 备注 |\n| --------------- | ------------------------------------------------------------ | ---- |\n| IPGet           | 返回客户端 IP                                                |      |\n| GetPubIP        | 获取公网ip, 如果两个ip不同，则访问ip.tool.lu 和false, ip都相同则返回true |      |\n| SubNetMaskToLen | ipv4 子网掩码长度换算                                        |      |\n| LenToSubNetMask | ipv4 网络位长度转换为子网掩码地址                            |      |\n| IsPublicIPv4    | ipv4 判断是否是公网ip                                        |      |\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserialt%2Fgopkg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserialt%2Fgopkg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserialt%2Fgopkg/lists"}