Try to abstract the main part.

This commit is contained in:
zicla
2019-04-27 23:24:09 +08:00
parent 14b6a74666
commit 2732b14eae
14 changed files with 130 additions and 105 deletions

View File

@ -40,8 +40,7 @@ func GetDevHomePath() string {
panic("cannot get dev home path.")
}
fmt.Println(file)
//$DevHomePath/code/tool/util/util_file.go
dir := GetDirOfPath(file)
dir = GetDirOfPath(dir)
dir = GetDirOfPath(dir)
@ -69,9 +68,11 @@ func GetHomePath() string {
//如果exPath中包含了 \\AppData\\Local\\Temp 我们认为是在Win的开发环境中
systemUser, err := user.Current()
winDev := strings.HasPrefix(exPath, systemUser.HomeDir+"\\AppData\\Local\\Temp")
if winDev {
exPath = GetDevHomePath() + "/tmp"
if systemUser != nil {
winDev := strings.HasPrefix(exPath, systemUser.HomeDir+"\\AppData\\Local\\Temp")
if winDev {
exPath = GetDevHomePath() + "/tmp"
}
}
return exPath

View File

@ -1,16 +1,14 @@
package util
//带有panic恢复的方法
func PanicHandler() {
if err := recover(); err != nil {
//TODO 全局日志记录
//LOGGER.Error("异步任务错误: %v", err)
}
}
func RunWithRecovery(f func()) {
defer func() {
if err := recover(); err != nil {
//TODO 全局日志记录
//LOGGER.Error("异步任务错误: %v", err)
}
}()
//带有panic恢复的方法
func SafeMethod(f func()) {
defer PanicHandler()
//执行函数
f()
}