# README
go函数库
使用方法
go get -u github.com/serialt/gopkg
# Functions
AESDecryptCBC AES CBC模式解密.
AESDecryptCFB AES CFB模式解密.
AESDecryptECB AES ECB模式解密.
AESDecryptGCM AESDecryptGCM AESDecryptGCM模式解密.
Decrypt gcm-aes base64解密为字符串 秘钥长度为16/24/32位.
AESDecryptOFB AES OFB模式解密.
AESEncryptCBC AES CBC模式加密.
AESEncryptCFB AES CFB模式加密.
AESEncryptECB AES ECB模式加密.
AESEncryptGCM AES GCM模式加密.
Encrypt gcm-aes base64加密字符串 秘钥长度为16/24/32位.
AESEncryptOFB AES OFB模式加密.
ArgsWithSpaces it like Println, will add spaces for each argument.
ArrayToString 数字切片变字符串.
AssertIV 判断AES向量长度是否合法.
AssertKey 判断AES密钥长度是否合法,密钥长度16/24/32字节.
BytesToInt 字节转换成int.
BytesToUint16 字节转换成uint16.
BytesToUint32 字节转换成uint32.
BytesToUint64 字节转换成uint64.
*
* @description: 判断字符串是否在切片里
* @author: Serialt
* @param slice {[]string}
* @param value {string}
* @return {bool}
*/ Contains Does slice contain string.
CopyFile copy file to another path.
CreateFile 创建空文件.
CreateFile create file if not exists Usage: CreateFile("path/to/file.txt", 0664, 0666).
CurrentShell get current used shell env file.
DataSize format bytes number friendly.
DeleteFile 删除文件或目录.
DeleteIfExist removes the named file or (empty) directory on exists.
DeleteIfFileExist removes the named file on exists.
DiffSlice sub是否在main里,返回sub里不在main里的元素,返回diff和bool.
DirExist 判断目录否存在.
DirNameFilterFunc filter filepath by given dir names.
DotDirFilterFunc filter dot dirname.
DotFileFilterFunc filter dot filename.
ElapsedTime calc elapsed time 计算运行时间消耗 单位 ms(毫秒).
EmptyFinder new empty FileFinder instance.
EnvGet 获取环境变量 envName 的值
envName 环境变量名称.
EnvGetBool 获取环境变量 envName 的 bool 值
envName 环境变量名称.
EnvGetD 获取环境变量 envName 的值
envName 环境变量名称
defaultValue 环境变量为空时的默认值.
EnvGetFloat64 获取环境变量 envName 的值
envName 环境变量名称.
EnvGetFloat64D 获取环境变量 envName 的值
envName 环境变量名称
defaultValue 环境变量为空时的默认值.
EnvGetInt 获取环境变量 envName 的值
envName 环境变量名称.
EnvGetInt64 获取环境变量 envName 的值
envName 环境变量名称.
EnvGetInt64D 获取环境变量 envName 的值
envName 环境变量名称
defaultValue 环境变量为空时的默认值.
EnvGetIntD 获取环境变量 envName 的值
envName 环境变量名称
defaultValue 环境变量为空时的默认值.
EnvGetUint64 获取环境变量 envName 的值
envName 环境变量名称.
EnvGetUint64D 获取环境变量 envName 的值
envName 环境变量名称
defaultValue 环境变量为空时的默认值.
Environ like os.Environ, but will returns key-value map[string]string data.
ExecCmd an command and return output.
ExpandPath will parse `~` as user home dir path.
ExtFilterFunc filter filepath by given file ext.
FileAppend 追加内容到文件中
filePath 文件地址
data 内容
force 如果文件已存在,会将文件清空
It returns the number of bytes written and an error.
FileCompressTar 压缩文件 files 文件数组,可以是不同dir下的文件或者文件夹 dest 压缩文件存放地址.
FileCompressZip 压缩文件 files 文件数组,可以是不同dir下的文件或者文件夹 dest 压缩文件存放地址.
FileCopy 拷贝文件
srcFilePath 源文件路径
dstFilePath 目标文件路径.
FileDeCompressZip 解压.
FileExists reports whether the named file or directory exists.
Suffix get filename ext.
FileLoopDirs 遍历目录下的所有子目录,即返回pathname下面的所有目录,目录为绝对路径.
FileLoopFileNames 遍历文件夹及子文件夹下的所有文件名,即返回pathname目录下所有的文件,文件名为相对路径.
FileLoopFiles 遍历文件夹及子文件夹下的所有文件,即返回pathname目录下所有的文件,文件名为绝对路径.
FileLoopOneDirs 遍历目录下的所有子目录,即返回pathname下面的所有目录,目录为相对路径.
FileModify 修改文件中指定位置的内容
filePath 文件地址
offset 以0为起始坐标的偏移量
data 内容
force 如果文件已存在,会将文件清空
It returns the number of bytes written and an error.
FileMove 移动文件.
FileParentPath 文件父路径.
FilePathExists 判断路径是否存在.
FileReadFirstLine 从文件中读取第一行并返回字符串数组.
FileReadLines 从文件中逐行读取并返回字符串数组.
FileReadPointLine 从文件中读取指定行并返回字符串数组.
FilterPrefix 根据前缀过滤slice.
FindCommandPath 获取命令的路径.
FindLongestStr 查询最长字符串.
FindUser find an system user by name.
Float convert value to float64.
GenerateRSAKey 创建RSA 常用位数 1024 2048 4096.
GenerateRSAKeyInFile 创建公私钥并写入文件.
GenerateRSAKeyWithPwd 创建带密码的RSA.
GetBytes 获取接口字节数组.
CurrentUser get current user.
GetDate 返回当前时间.
GetDirListWithFilter get directory list with filter.
GetFilepaths get all filepaths in a directory tree.
GetFiles get files.
GetHmacMD5Sign 获取hmac md5签名.
GetHmacSHA1Sign 获取hmac sha1签名.
GetHmacSHA256Base64Sign 获取hmac sha256base64签名.
GetHmacSHA256Sign 获取hmac sha256签名.
GetHmacSha384Sign 获取hmac sha384签名.
GetHmacSHA512Base64Sign 获取hmac sha512base64签名.
GetHmacSHA512Sign 获取hmac sha512签名.
GetLoginUser get current user, alias of CurrentUser.
获取公网ip, 如果两个ip不同,则访问ip.tool.lu 和false, ip都相同则返回true.
GetRandomNumeral 获取随机自然数字符串.
GetRandomString 获取随机字符串.
获取项目路径.
GetRunTime 获取当前系统环境.
GlobFilterFunc filter filepath by given patterns.
HashMD5 MD5.
HashMD516 MD516.
HashMD516Bytes MD516Bytes.
HashMD5Bytes MD5Bytes.
HashSha1 Sha1.
HashSha1Bytes Sha1Bytes.
HashSha224 Sha224.
HashSha224Bytes Sha224Bytes.
HashSha256 Sha256.
HashSha256Bytes Sha256Bytes.
HashSha384 Sha384.
HashSha384Bytes Sha384Bytes.
HashSha512 Sha512.
HashSha512Bytes Sha512Bytes.
HasShellEnv has shell env check.
HomeDir get user home dir path, alias .
Hostname is alias of os.Hostname, but ignore error.
HowLongAgo format a seconds, get how lang ago.
IndexSlice 查找string在slice的索引.
Int convert value to int.
Int64 convert string to int64.
IntOrPanic convert value to int, will panic on error.
IntToBytes int转换成字节.
IPGet 返回客户端 IP.
No description provided by the author
IsAbsPath is abs path.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
IsConsole check out is in stderr/stdout/stdin
Usage: sysutil.IsConsole(os.Stdout).
No description provided by the author
IsDir 判断目录否存在.
No description provided by the author
No description provided by the author
IsFile reports whether the named file or directory exists.
No description provided by the author
IsImageFile check file is image file.
No description provided by the author
No description provided by the author
No description provided by the author
IsMSys msys(MINGW64) env,不一定支持颜色.
No description provided by the author
IsNumeric returns true if the given character is a numeric, otherwise false.
No description provided by the author
No description provided by the author
IsPublicIPv4 ipv4 判断是否是公网ip.
No description provided by the author
IsShellSpecialVar reports whether the character identifies a special shell variable such as $*.
IsSubSlice Is a sub-slice of slice.
IsTerminal isatty check
Usage: sysutil.IsTerminal(os.Stdout.Fd()).
No description provided by the author
IsWindows system.
IsZipFile check is zip file.
LenToSubNetMask ipv4 网络位长度转换为子网掩码地址 如 24 对应的子网掩码地址为 255.255.255.0.
Md5File 计算文件的md5值.
Md5String 加密字符串.
Md5StringUpper 加密字符串变大写.
Md5Sum 计算md5值.
Md5SumUpper 计算md5值的大写字母.
MimeType get File Mime Type name.
Mkdir alias of os.MkdirAll().
创建文件夹,支持x/a/a 多层级.
MkParentDir quick create parent dir.
Mode get file mode.
ModTimeFilterFunc filter file by modify time.
MustCopyFile copy file to another path.
MustCreateFile create file, will panic on error.
MustFloat convert value to float64.
MustInt convert value to int.
MustInt64 convert.
MustReadFile read file contents, will panic on error.
MustRemove removes the named file or (empty) directory.
MustUint convert string to uint.
Name get file/dir name 获取路径的文件名.
NewFinder new instance with source dir paths.
OpenFile like os.OpenFile, but will auto create dir.
OSTempDir creates a new temp dir on os.TempDir and return the temp dir path Usage: fsutil.OSTempDir("example.*.txt").
OSTempFile create an temp file on os.TempDir() Usage: fsutil.OSTempFile("example.*.txt").
*
* @description: 读取excel文件数据
* @author: serialt
* @param filepath {string}
* @param fileHeader {[]string}
* @param skipHeader {bool}
* @return {error}
*/.
*
* @description: 写入数据到excel文件
* @author: serialt
* @param filepath {string}
* @param sheet {string}
* @param data {[][]string}
* @return {error}
*/.
Dir get dir path, without last name.
PathNameFilterFunc filter filepath by given path names.
Percent returns a values percent of the total.
Pinyin 汉字转拼音,当多音字时候取第一个.
Prefix 获取文件名前缀, /tmp/main.go 获取的文件前缀是main.
PrettyJSON get pretty Json string.
QuickOpenFile like os.OpenFile.
QuietRemove removes the named file or (empty) directory.
RandInt64 生成int64随机数.
RandInt64Crypto 通过crypto库生成int64随机数.
RandomInt return an random int at the min ~ max Usage: RandomInt(10, 99) RandomInt(100, 999) RandomInt(1000, 9999).
RandRangeInt 获取min和max之前的随机数.
ReaderMimeType get the io.Reader mimeType Usage: file, err := os.Open(filepath) if err != nil { return } mime := ReaderMimeType(file).
ReadExistFile read file contents if exist, will panic on error.
ReadFile 读文件.
Realpath parse and get.
RecreateDir recreate dir.
RegexFilterFunc filter filepath by given regex pattern
Usage: f := EmptyFiler() f.AddFilter(RegexFilterFunc(`[A-Z]\w+`, true)).
RsaDecrypt rsa解密.
RSADecryptOAEP 私钥解密.
RSAEncrypt rsa加密.
RSAEncryptOAEP 公钥加密.
RsaSignPKCS1v15 rsa签名.
RsaVerifySignPKCS1v15 rsa验证签名.
RunCmd 获取标准正确输出.
RunCMD 标准正确错误输出到标准正确输出.
RunCommandWithTimeout 带超时控制的执行shell命令.
ScaleDDuoStringToInt64 int字符串转int.
ScaleDDuoStringToUint64 int字符串转int.
ScaleDuoStringToInt64 int字符串转int.
ScaleDuoStringToUint64 int字符串转int.
ScaleFloat64toInt64 将float64转成精确的int64.
ScaleHexStringToInt64 int字符串转int.
ScaleHexStringToUint64 int字符串转int.
ScaleInt32Len 计算整型字符串长度.
ScaleInt32ToDDuoString int32转十六进制字符串.
ScaleInt32ToDuoString int32转十六进制字符串.
ScaleInt32ToHexString int32转十六进制字符串.
ScaleInt64Len 计算整型字符串长度.
ScaleInt64ToDDuoString int64转十六进制字符串.
ScaleInt64ToDuoString int64转十六进制字符串.
ScaleInt64toFloat64 将int64恢复成正常的float64.
ScaleInt64ToHexString int64转十六进制字符串.
ScaleIntLen 计算整型字符串长度.
ScaleIntToDDuoString int转64进制字符串.
ScaleIntToDuoString int转十六进制字符串.
ScaleIntToHexString int转十六进制字符串.
ScaleUint32Len 计算整型字符串长度.
ScaleUint32ToDDuoString uint32转十六进制字符串.
ScaleUint32ToDuoString uint32转十六进制字符串.
ScaleUint32toFullState 补全不满十位数状态,如1->0000000001、34->0000000034、215->0000000215.
ScaleUint32ToHexString uint32转十六进制字符串.
ScaleUint64Len 计算整型字符串长度.
ScaleUint64ToDDuoString uint64转十六进制字符串.
ScaleUint64ToDuoString uint64转十六进制字符串.
ScaleUint64ToHexString uint64转十六进制字符串.
ScaleUint8toFullState 补全不满三位数状态,如1->001、34->034、215->215.
ScaleUintLen 计算整型字符串长度.
ScaleUintToDDuoString int转64进制字符串.
ScaleUintToDuoString uint转十六进制字符串.
ScaleUintToHexString uint转十六进制字符串.
No description provided by the author
StdIsTerminal os.Stdout is terminal.
*
* @description: String2Timestamp 字符串转时间戳
* @author:
* @param date {string} 待转换时间字符串 如:2019/09/17 10:16:56
* @param format {string} 时间字符串格式化类型 如:2006/01/02 15:04:05
* @param zone {*time.Location} zone 时区 如:time.Local / time.UTC
* @return {int64,error}
*/.
StringBuild 拼接字符串.
StringBuildSep 拼接字符串.
StringConvert 下划线转换,首字母小写变大写, 下划线去掉并将下划线后的首字母大写.
StringIsEmpty 判断字符串是否为空,是则返回true,否则返回false.
StringAllLetter 判断字符串是否只由字母组成.
StringIsNotEmpty 和 IsEmpty 的语义相反.
StringPrefixSupplementZero 当字符串长度不满足时,将字符串前几位补充0.
StringRandSeq 创建指定长度的随机字符串.
StringRandSeq16 创建长度为16的随机字符串.
StringSingleSpace 将字符串内所有连续空格替换为单个空格.
StringSingleValue 将字符串内所有连续value替换为单个value.
StringsToInts string slice to int slice.
StringTrim 去除字符串中的空格和换行符.
StringTrimN 去除字符串中的换行符.
StructToMap 结构体转map.
SubNetMaskToLen ipv4 子网掩码长度换算 如 255.255.255.0 对应的网络位长度为 24.
SubString 截取字符串.
Suffix get filename ext.
SuffixFilterFunc filter filepath by given file ext.
TempDir creates a new temp dir and return the temp dir path Usage: fsutil.TempDir("", "example.*.txt").
TempFile is alias of ioutil.TempFile Usage: fsutil.TempFile("", "example.*.txt").
*
* @description: Timestamp2String 时间戳转字符串
* @author:
* @param timestampSec {int64 } 时间戳秒值
* @param timestampNSec {int64} 时间戳纳秒值
* @param format {string} 时间字符串格式化类型 如:2006/01/02 15:04:05
* @param zone {*time.Location}
* @return {string}
*/.
ToFloat convert value to float64.
ToInt convert string to int.
ToInt64 convert string to int64.
ToString 将对象格式化成字符串.
ToUint convert string to uint.
TranslateCh2En 谷歌翻译中文转英文.
TranslateEn2Ch 谷歌翻译英文转中文.
TrimSpace 去除空格.
Uint convert string to uint.
Uint16ToBytes uint16转换成字节.
Uint32ToBytes uint32转换成字节.
Uint64ToBytes uint64转换成字节.
Unzip a zip archive from https://blog.csdn.net/wangshubo1989/article/details/71743374.
UserCacheDir will prepend user `$HOME/.cache` to subPath.
UserConfigDir will prepend user `$HOME/.config` to subPath.
UserDir will prepend user home dir to subPath.
UserHomeDir get user home dir path.
UserHomePath 用户的家目录.
Where 获取命令的路径,FindCommandPath的别名.
Workdir get.
WriteFile 写文件.
WriteStringToFile write string to file.
# Constants
No description provided by the author
No description provided by the author
MimeSniffLen sniff Length, use for detect file mime type.
# Variables
当前项目根目录.
perm and flags for create log file.
No description provided by the author
No description provided by the author
ErrConvertFail convert error.
图片处理 ImageMimeTypes refer net/http package.
alias methods.
alias methods.
No description provided by the author
# Structs
File template file.
FileFinder struct.
FileMeta struct.
FindResults struct.
No description provided by the author
# Type aliases
DirFilterFunc for filter file path.
FileFilterFunc for filter file path.
Filter file filter.
FilterFunc for filter file path.