Documentation ¶
Index ¶
- Constants
- Variables
- func ArgsToConfigMap(args ...string) map[string]string
- func ArrayInsertArrayStr(arr []string, els ...string) []string
- func ArrayNewArrayInt(arr []int, values ...int) []int
- func ArrayNewArrayStr(arr []string, values ...string) []string
- func ArrayNewInt(array ...int) []int
- func ArrayNewStr(array ...string) []string
- func ArrayPrintln(values ...string)
- func ArrayRemoveArrayStr(arr []string, removeIndex int) []string
- func Boolean(b string) bool
- func BooleanOf(b string) bool
- func ByteParse(v string) int8
- func CRC32(str string) int
- func CRC32Hash(bytes []byte) uint32
- func CRC32_(bytes []byte) int
- func CheckSum(data []byte) uint16
- func CmdDirRun(dir string, commandName string, params ...string) string
- func CmdGenerateBecomeSilentString(fileApp string, arg string) string
- func CmdOnlyRun(commandName string, params ...string) error
- func CmdRun(commandName string, params ...string) string
- func CmdRunByBat(commandLine string) string
- func CmdRunLine(commandLine string)
- func CmdStartApp(becomeSilent bool, cmdArray ...string) error
- func CmdStartAppLine(becomeSilent bool, cmd string) error
- func CmdWrapPathString(arg string) string
- func CmdWrapPathStrings(args ...string) []string
- func ConfigMapReadFile(fileConfig string) map[string]string
- func ConfigMapWriteFile(configMap map[string]string, fileConfig string)
- func Debounce(delay time.Duration, fn func()) func()
- func EnvIsDev() bool
- func FileCopy(srcFile string, destFile string) bool
- func FileCreateDirs(path string) bool
- func FileDelete(file string) bool
- func FileDirsReadyForWriteFile(file string) bool
- func FileExists(path string) bool
- func FileFindOnlyResource(root string, names ...string) string
- func FileFindOnlyResourceName(root string, names ...string) string
- func FileFindOnlyResourcePath(paths ...string) string
- func FileGetAPPLocal() string
- func FileGetChildren(file string) []string
- func FileGetCurrentDir() string
- func FileGetCurrentFilePath() string
- func FileGetDirs(file string) []string
- func FileGetExecDir() string
- func FileGetExecFile() string
- func FileGetFilename(file string) string
- func FileGetFiles(file string) []string
- func FileGetName(file string) string
- func FileGetParentDir(file string) string
- func FileGetSuffix(file string) string
- func FileGetUserDir() string
- func FileIsAbsolutePath(file string) bool
- func FileIsDir(path string) bool
- func FileIsFile(path string) bool
- func FileIsFileByFilename(file string) bool
- func FileOf(filePaths ...string) string
- func FilePathSeparator() string
- func FileRead(file string) string
- func FileReadBytes(file string) []byte
- func FileReadBytesIfExists(defaultValue []byte, filePaths ...string) []byte
- func FileRename(oldFile string, newFile string) error
- func FileSeparator() string
- func FileSumCheckByCRC32(file1, file2 string) bool
- func FileWrite(file string, content string) bool
- func FileWriteBytes(file string, bytes []byte) bool
- func FloatParse(v string) float64
- func HttpDownload(url string, file string, headers ...string) error
- func HttpGet(url string, headers ...string) (string, error)
- func HttpGetToBytes(url string, headers ...string) ([]byte, error)
- func HttpPost(url string, data []byte, headers ...string) (string, error)
- func InitLog(followExe bool, names ...string)
- func InstanceOf(objectPtr interface{}) string
- func IntParse(v string) int
- func IsInstanceOf(objectPtr, typePtr interface{}) bool
- func IsStartUp(name string) bool
- func IsUrl(url string) bool
- func JsonGetValueByKey(jsonObject JSONObject, key string) interface{}
- func JsonGetValueByKeys(jsonObject JSONObject, keys ...string) interface{}
- func JsonToString(object interface{}) string
- func ListToArrayInt(lst *list.List) []int
- func ListToArrayStr(lst *list.List) []string
- func LongParse(v string) int64
- func MD5(str string) string
- func MD5Hash(bytes []byte) [16]byte
- func MD5_(bytes []byte) string
- func Notify(title string, content string) bool
- func NotifyError(content string)
- func NotifyInfo(content string)
- func NotifyMac(title, message string) string
- func NotifyWinBat(title, message string, icon NotifyIcon) string
- func ParseArgs()
- func Ping(domain string)
- func Ping_(domain string) bool
- func RegexContains(str, regex string) bool
- func RegexFind(text, regex string) string
- func RegexGet(text, regex string) ([]string, error)
- func RegexGetFirstMatch(text, regex string) (string, error)
- func RegexIsMatch(text, regex string) (bool, error)
- func RegexReplace(str, regex, replace string) string
- func SHA1(str string) string
- func SHA1Hash(bytes []byte) [20]byte
- func SHA1_(bytes []byte) string
- func ScheduledTask(time_ time.Time, taskName, taskPath, timeStr string)
- func ScheduledTaskDelete(taskName string)
- func ShortParse(v string) int16
- func StartMacApp(becomeSilent bool, fileApp string, arg string) error
- func StartUpBySelf(on bool, name string)
- func StartWinApp(becomeSilent bool, fileApp string, arg string) error
- func StrEndsWith(str string, ends string) bool
- func StrEqualIgnoreCase(str1 string, str2 string) bool
- func StrIsEmpty(obj any) bool
- func StrIsNotEmpty(obj any) bool
- func StrJoin(separator string, strs ...string) string
- func StrJoinObj(separator string, objs ...interface{}) string
- func StrRandom(length int) string
- func StrSplit(str, separator string) []string
- func StrSplitByRegexp(str string, separators string) []string
- func StrStartsWith(str string, starts string) bool
- func StrSubstring(str string, begin int, end int) string
- func StrSubstringBegin(str string, begin int) string
- func StrSubstringEnd(str string, end int) string
- func StrToUpperByFirstLetter(s string) string
- func StrTrim(str string) string
- func StrUrlDecode(encodedStr string) string
- func StrUrlEncode(plainText string) string
- func TestIntRange()
- func ThrowException(errors ...any)
- func TimeIntToTime(seconds int64) time.Time
- func TimeIntToTimeString(seconds int64) string
- func TimeNow() time.Time
- func TimeNowString() string
- func TimePlus(t time.Time, years, months, days int) time.Time
- func TimePlusDay(t time.Time, day int) time.Time
- func TimePlusHour(t time.Time, hours int) time.Time
- func TimePlusMinute(t time.Time, minutes int) time.Time
- func TimePlusMonth(t time.Time, months int) time.Time
- func TimePlusSecond(t time.Time, seconds int) time.Time
- func TimePlusWeek(t time.Time, week int) time.Time
- func TimePlusYear(t time.Time, years int) time.Time
- func TimeSleep(millisecond int)
- func TimeStringToTime(t string) time.Time
- func TimeToString(t time.Time) string
- func TimeToStringFormat(t time.Time, format string) string
- func ToString(obj any) string
- func TxtToConfigMap(config string) map[string]string
- func TxtToConfigMapBy(config, firstSplit, secondSplit string) map[string]string
- func Usage()
- type Debouncer
- type HeaderPair
- type ICMP
- type JSONArray
- type JSONObject
- func HttpPostJSON(url string, jsonData interface{}, headers ...string) (JSONObject, error)
- func JsonBytesToJson(bytes []byte) JSONObject
- func JsonGetValueToMap(jsonObject JSONObject, keys ...string) (JSONObject, error)
- func JsonGetValueToMap120(json JSONObject, keys ...string) (JSONObject, error)
- func JsonStrToJson(str string) JSONObject
- type NotifyIcon
Constants ¶
const ( ICON_INFO = NotifyIcon("information") ICON_ERROR = NotifyIcon("error") ICON_WARNING = NotifyIcon("warning") )
const TimeFormat = "2006-01-02 15:04:05"
Variables ¶
var ( IsWindows = runtime.GOOS == "windows" IsLinux = runtime.GOOS == "linux" IsMac = runtime.GOOS == "darwin" )
var HttpTimeout = 0
设置超时时间 注意:超时包括连接时间、任何重定向和读取响应正文。 设置为0,则不设置
var ( // 创建一个新的时区(定义北京时间相对于 UTC 的偏移量) TIMEZONE = time.FixedZone("Asia/Shanghai", 8*60*60) )
const TIMEZONE *time.Location
Functions ¶
func ArgsToConfigMap ¶
ArgsToConfigMap 将参数数组解析成map 只有-key=value会被解析,如:-s=123
func ArrayInsertArrayStr ¶
ArrayInsertArrayStr 向数组arr前排插入元素。 如果向后最近请直接使用 append(slice []Type, elems ...Type)
func ArrayNewArrayInt ¶
ArrayNewArrayInt 变长数组,多次重复使用的话有点消耗性能
func ArrayNewArrayStr ¶
ArrayNewArrayStr 变长数组,多次重复使用的话有点消耗性能
func ArrayNewInt ¶
func ArrayNewStr ¶
func ArrayPrintln ¶
func ArrayPrintln(values ...string)
func ArrayRemoveArrayStr ¶
ArrayRemoveArrayStr 变长数组,多次重复使用的话有点消耗性能
func CmdGenerateBecomeSilentString ¶
生成静默启动的执行命令(带PowerShell.exe)
func CmdOnlyRun ¶
func CmdRunByBat ¶
CmdRunByBat 通过生成bat文件执行命令,然后删掉。(一些特殊系统命令无法直接调用)
func CmdRunLine ¶
func CmdRunLine(commandLine string)
执行命令并返回结果
参数 commandLine 一行可执行命令,如:PowerShell.exe xxx
return 返回预期的值即为成功
func CmdWrapPathString ¶
目标程序或参数有空格或者?时,则需要用单引号包裹,如:arg=>'arg'
func CmdWrapPathStrings ¶
目标程序或参数有空格,则需要用单引号包裹,如:arg=>'arg'
func ConfigMapReadFile ¶
func ConfigMapWriteFile ¶
func FileCreateDirs ¶
func FileDelete ¶
FileDelete 删除文件,可能会抛出异常 不能中断的地方建议用err :=recover()接收抛出的异常
defer func() { if err := recover(); err != nil { fmt.Println("occur error") fmt.Println(err) } }()
func FileDirsReadyForWriteFile ¶
FileDirsReadyForWriteFile 提前向准备写入的文件目录做准备 true表示存在已经准备就绪
func FileFindOnlyResource ¶ added in v0.0.4
根据跟路径分别拼接资源文件目录名,如果存在则返回目录路径,不存在返回第一个目录路径
func FileFindOnlyResourceName ¶ added in v0.0.4
根据跟路径分别拼接资源文件目录名,如果存在则返回,不存在返回第一个名字
func FileFindOnlyResourcePath ¶ added in v0.0.4
根据提供的绝对路径寻找存在的资源目录,如果存在则返回目录路径,不存在返回第一个目录路径
func FileGetAPPLocal ¶
func FileGetAPPLocal() string
FileGetAPPLocal 获取用户的本地应用数据目录,如C:\Users\zhangsan\AppData\Local
func FileGetCurrentFilePath ¶
func FileGetCurrentFilePath() string
FileGetCurrentFilePath 获取exe执行文件路径(最终方案-全兼容)包含后缀
func FileGetExecFile ¶
func FileGetExecFile() string
func FileIsFileByFilename ¶
FileIsFileByFilename 根据文件名后缀来判断是否为文件(无法判别无后缀的文件)
func FileReadBytes ¶
func FileReadBytesIfExists ¶
func FileSumCheckByCRC32 ¶
FileSumCheckByCRC32 通过CRC32校验两个文本是否一致
func FileWriteBytes ¶
func InitLog ¶
InitLog 初始化日志设置
followExe 否跟随执行文件,true日志文件在执行文件目录下,false则在用户目录下。
names 可以不设置,多个将会拼接 尽量只是文件名
fatal系列函数会在写入日志信息后调用os.Exit(1)。Panic系列函数会在写入日志信息后panic。
log.Fatalln("fatal系列函数会在写入日志信息后调用os.Exit(1)")
log.Panicln("执行后会自动触发一个异常")
func InstanceOf ¶
func InstanceOf(objectPtr interface{}) string
func IntParse ¶
int32:带符号的32位整数,取值范围从 -2,147,483,648 到 2,147,483,647。(由于int在32位系统上通常是32位,在64位系统上通常是64位)
func IsInstanceOf ¶
func IsInstanceOf(objectPtr, typePtr interface{}) bool
IsInstanceOf sample variables
someString :="Some String" someFloat := float32(2.4) someStruct1 := SomeStruct1{} someStruct2 := SomeStruct2{} someStruct1Ptr := &SomeStruct1{} // primitive string fmt.Println("string <-> *string \\t\\t", IsInstanceOf(someString, (*string)(nil))) //false fmt.Println("*string <-> *string \\t\\t", IsInstanceOf(&someString, (*string)(nil))) //true // primitive float32 fmt.Println("float32 <-> *float32 \\t\\t", IsInstanceOf(someFloat, (*float32)(nil))) //false fmt.Println("*float32 <-> *float32 \\t\\t", IsInstanceOf(&someFloat, (*float32)(nil))) //true // structure fmt.Println("SomeStruct1 <-> *SomeStruct1 \\t", IsInstanceOf(someStruct1, (*SomeStruct1)(nil))) //false fmt.Println("*SomeStruct1 <-> *SomeStruct1 \\t", IsInstanceOf(&someStruct1, (*SomeStruct1)(nil))) //true fmt.Println("*SomeStruct2 <-> *SomeStruct1 \\t", IsInstanceOf(&someStruct2, (*SomeStruct1)(nil))) //false fmt.Println("*SomeStruct1 <-> *SomeStruct1 \\t", IsInstanceOf(someStruct1Ptr, (*SomeStruct1)(nil))) //true
func JsonGetValueByKey ¶
func JsonGetValueByKey(jsonObject JSONObject, key string) interface{}
通过key取值,如:JsonGetValueByKey(response,"data.token")【注意:可能为nil】
func JsonGetValueByKeys ¶
func JsonGetValueByKeys(jsonObject JSONObject, keys ...string) interface{}
通过key取值,如:JsonGetValueByKey(response,"data","token")【注意:可能为nil】
func ListToArrayInt ¶
func ListToArrayStr ¶
func NotifyError ¶
func NotifyError(content string)
func NotifyInfo ¶
func NotifyInfo(content string)
func NotifyWinBat ¶
func NotifyWinBat(title, message string, icon NotifyIcon) string
func Ping ¶
func Ping(domain string)
func main() {
ParseArgs() args := os.Args if len(args) < 2 { Usage() } desIp := args[len(args)-1] Ping(desIp) }
func RegexGetFirstMatch ¶
RegexGetFirstMatch 获取第一个匹配值(不包含文本本身)
func RegexReplace ¶ added in v0.0.3
RegexReplace 替换正则表达式中的部分
RegexReplace("-w -s", `\s`, "@") => -w@-s,将一个空格替换为@
RegexReplace("hi,$张三$! $李四$ 你们好。", `\$([^$]+)\$`, "<$1>") => hi,<张三>! <李四> 你们好。
匹配@开头结尾的如:`\@([^@]+)\@`。<$1>其中的$1代表第一个捕获组的内容
func ScheduledTask ¶
ScheduledTask 定时任务
func StartUpBySelf ¶
StartUpBySelf 自启动 实现原理是在LaunchAgents目录下写入启动配置文件配置说明。 win则是在用户启动目录下写入一个bat来启动当前二进制。 https://p00q.cn/?p=707 https://www.fythonfang.com/blog/2021/4/19/mac-launchd-daemons-and-agents-tutorial C:\Users\user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
func StartWinApp ¶
启动其他程序
参数:becomeSilent 静默启动标识
参数:fileApp 待启动程序路径+名称
参数:arg 待启动程序传入参数
retrun err!=nil就是成功,其他错误 参考testStartWinApp
https://www.bbsmax.com/A/VGzlk4NYdb/
https://blog.csdn.net/hejingdong123/article/details/101369709
func StrEndsWith ¶
func StrEqualIgnoreCase ¶
func StrIsEmpty ¶
func StrIsNotEmpty ¶
func StrJoinObj ¶
StrJoinObj 接受任意数量的interface{}参数,尝试将它们转换为字符串并用指定分隔符连接
func StrSplitByRegexp ¶
StrSplitByRegexp(str,"@#*") 根据分割符号【集】separators拆分成数组(不包含分割符号集separators)
func StrStartsWith ¶
func StrSubstringBegin ¶
func StrSubstringEnd ¶
func StrToUpperByFirstLetter ¶
func StrUrlDecode ¶
func StrUrlEncode ¶
func TestIntRange ¶
func TestIntRange()
func ThrowException ¶
func ThrowException(errors ...any)
func TimeIntToTime ¶
func TimeIntToTimeString ¶
TimeIntToTimeString 2006-01-02 15:04:05
func TimeStringToTime ¶
TimeStringToTime 2006-01-02 15:04:05
func TimeToStringFormat ¶
TimeToStringFormat 可以使用yyyy-MM-dd HH:mm:ss
func TxtToConfigMap ¶
TxtToConfigMap 将config 通过 \n 分成lines 再通过 @= 分成key-value 。#开头将被跳过
func TxtToConfigMapBy ¶ added in v0.0.5
TxtToConfigMapBy 将config 通过 firstSplit 分成lines 再通过 secondSplit 分成 key-value。#开头将被跳过
Types ¶
type Debouncer ¶
type Debouncer struct {
// contains filtered or unexported fields
}
func NewDebouncer ¶
type HeaderPair ¶
type JSONObject ¶
type JSONObject map[string]interface{}
ResponseJSON 是用来存储响应体的通用 JSON 结构体 打印返回的 JSON 响应 fmt.Printf("Response JSON: %+v\n", *response)
func HttpPostJSON ¶
func HttpPostJSON(url string, jsonData interface{}, headers ...string) (JSONObject, error)
func JsonGetValueToMap ¶
func JsonGetValueToMap(jsonObject JSONObject, keys ...string) (JSONObject, error)
将深度json根据keys扁平化,result, err := common.JsonGetValueToMap(jsonObj, "result.token", "result.authMenu.10.authed")
func JsonGetValueToMap120 ¶
func JsonGetValueToMap120(json JSONObject, keys ...string) (JSONObject, error)
var current interface{} = response for i, key := range keys { keysSlice := strings.Split(key, ".") for _, k := range keysSlice { if m, ok := current.(map[string]interface{}); ok { current = m[k] if current == nil { // 当键不存在时,将结果设为空 results[i] = nil break } } else { // 当遇到非映射类型时,后续键无法处理,将结果设为空 results[i] = nil break } } results[i] = current } return results }
type NotifyIcon ¶
type NotifyIcon string