common

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayContains

func ArrayContains(array []string, val string) bool

ArrayContains array中是否存在指定数据

func ArrayContainsNums

func ArrayContainsNums(s []string, substr []string) int

ArrayContainsNums 统计连个数组中相同值的个数

func Base64Decode

func Base64Decode(src string) ([]byte, error)

func Base64Encode

func Base64Encode(src []byte) string

func Byte2Int

func Byte2Int(data []byte) int

Byte2Int 从[]byte中读取长度(小端)

func BytesMerger

func BytesMerger(b1, b2 []byte) []byte

BytesMerger 合并[]byte

func CleanFile

func CleanFile(path string)

CleanFile 清空文件

func CommandContext

func CommandContext(name string, arg ...string) (string, error)

CommandContext 执行命令 默认超时时间60秒

func ConfigViper

func ConfigViper(path string) (*viper.Viper, error)

ConfigViper 读指定位置配置文件

func ContainsDuplicate

func ContainsDuplicate(str []string) bool

ContainsDuplicate 检测数组是否包含重复元素 重复返回true

func CreateMutiDir

func CreateMutiDir(filePath string) error

CreateMutiDir 调用os.MkdirAll递归创建文件夹

func FileExistNotDir

func FileExistNotDir(filename string) error

FileExistNotDir FileExists 检查文件是否存在,并且不是目录

func FileIsExist

func FileIsExist(filename string) bool

FileIsExist 判断文件夹或文件是否存在, true为存在

func FileListFromPath

func FileListFromPath(fp string) ([]string, error)

FileListFromPath 获取文件夹下文件列表,支持通配符*

func FileModTime

func FileModTime(fp string) (int64, error)

FileModTime 获取文件修改时间 返回unix时间戳

func FilePathInfo

func FilePathInfo(fp string) (string, string, string)

FilePathInfo return 目录,文件名,后缀

func FileSize

func FileSize(fp string) (int64, error)

FileSize 获取文件大小

func FilesAndDirs

func FilesAndDirs(fp, filter string) (files []string, dirs []string, err error)

FilesAndDirs 获取指定目录下的所有文件和目录,不包含子目录

func FindAllFiles

func FindAllFiles(fp, filter string) (files []string, err error)

FindAllFiles 获取指定目录下的所有文件,包含子目录下的文件

func FindLineIndex

func FindLineIndex(ctx, sep string) (int, error)

FindLineIndex 根据关键字查找字符串索引行 返回行号

func FindRegexGroup1

func FindRegexGroup1(str, regexStr string) ([]string, error)

FindRegexGroup1 使用正则表达式regexStr在str中查找内容

func GetMaxValue

func GetMaxValue(numVal []int) (int, error)

GetMaxValue 获取最大值

func GetMinValue

func GetMinValue(numVal []int) (int, error)

GetMinValue 获取最小值

func GetNumberValueArray

func GetNumberValueArray(getValArray []string) ([]int, error)

GetNumberValueArray 从字符串数组中获取数字,取数组[0],没有数字会报错

func GetUUID

func GetUUID() string

func Int2Byte

func Int2Byte(data, len int) (ret []byte)

Int2Byte 将int写入指定长度的[]byte(小端)

func IsExist

func IsExist(fp string) bool

IsExist 判断文件夹或文件是否存在

func IsFile

func IsFile(fp string) bool

IsFile 判断是文件还是目录

func IsFileName

func IsFileName(fileName string) bool

func IsZip

func IsZip(zipPath string) bool

func Len

func Len(str string) int

Len 字符串长度,汉字算1个

func NotValue

func NotValue(input, seq, defaultVal string) string

NotValue 当input不等于指定值时返回默认值defaultVal

func Or

func Or(input, defaultVal string) string

Or 当input为空值时返回默认值default

func OrValue

func OrValue(input, seq, defaultVal string) string

OrValue 当input为指定值时返回默认值defaultVal

func PathFileExists

func PathFileExists(path string) (bool, error)

PathFileExists 判断文件路径是否存在

func PathInfo

func PathInfo(fp string) (string, string, string)

PathInfo 获取目录,文件名,后缀

func Random

func Random(n uint) []byte

Random 随机制定长度[]byte,主要用于产生对称key

func ReadFile

func ReadFile(filePathName string) (string, error)

func ReadLine

func ReadLine(lineNumber int, path string) string

ReadLine 读取指定行的内容 0行开始

func RemoveRepeatedElement

func RemoveRepeatedElement(arr []string) (newArr []string)

RemoveRepeatedElement 删除重复元素

func ReplaceFileContent

func ReplaceFileContent(filename, regexStr, repl string) error

ReplaceFileContent 使用正则表达式查找模式,并且替换正则1号捕获分组为指定的内容

func ReplaceFileKeywords

func ReplaceFileKeywords(filename, str, repl string) error

ReplaceFileKeywords 字符串替换,并且替换正则1号捕获分组为指定的内容

func ReplaceRegexGroup1

func ReplaceRegexGroup1(str, regexStr, repl string) (string, error)

ReplaceRegexGroup1 使用正则表达式regexStr在str中查找内容,并且替换正则1号捕获分组为指定的内容

func SearchFileContent

func SearchFileContent(filename, regexStr string) ([]string, error)

SearchFileContent 使用正则表达式查找模式正则1号捕获分组

func SearchPatternLines

func SearchPatternLines(str, boundaryRegexStr, captureGroup1Regex string) ([]string, error)

SearchPatternLines 使用正则表达式boundaryRegexStr在str中查找大块, 然后在大块中用captureGroup1Regex中的每行寻找匹配

func SearchPatternLinesInFile

func SearchPatternLinesInFile(filename, boundaryRegexStr, captureGroup1Regex string) ([]string, error)

SearchPatternLinesInFile 使用正则表达式boundaryRegexStr在文件filename中查找大块, 然后在大块中用captureGroup1Regex中的每行寻找匹配

func SelfPath

func SelfPath() string

SelfPath 获取当前目录

func ShellExec

func ShellExec(shellPath string) (string, error)

func StartTimer

func StartTimer(f func(), cycle time.Duration, hour int)

StartTimer cycle 天之后的 hour 点执行

func StringPrefixEqualCount

func StringPrefixEqualCount(str1, str2 string) int

StringPrefixEqualCount 判断连续相同的字符串个数

func StripUnprintable

func StripUnprintable(str string) string

StripUnprintable 仅使用可见字符

func TimeFormat

func TimeFormat(layout ...string) string

TimeFormat 格式化时间,参数为空时,默认格式化为 200601021504

func TrimValueFromArray

func TrimValueFromArray(strArray []string, trimValue string) []string

TrimValueFromArray 去除数组中指定元素

func UnZip

func UnZip(zipPath, password, decompressPath string) error

UnZip password值可以为空"" 当decompressPath值为"./"时,解压到相对路径

func WriteFile

func WriteFile(filePathName, content string) error

func Zip

func Zip(zipPath, password string, fileList []string) error

Zip password值可以为空""

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL