Try to abstract the main part.
This commit is contained in:
@ -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
|
@ -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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user