Refine the structure of this project.
This commit is contained in:
@ -1,8 +1,7 @@
|
||||
package util
|
||||
|
||||
|
||||
//带有panic恢复的方法
|
||||
func PanicHandler() {
|
||||
func PanicHandler() {
|
||||
if err := recover(); err != nil {
|
||||
//TODO 全局日志记录
|
||||
//LOGGER.Error("异步任务错误: %v", err)
|
||||
@ -10,11 +9,15 @@ func PanicHandler() {
|
||||
}
|
||||
|
||||
//带有panic恢复的方法
|
||||
func SafeMethod(f func()) {
|
||||
func SafeMethod(f func()) {
|
||||
defer PanicHandler()
|
||||
//执行函数
|
||||
f()
|
||||
}
|
||||
|
||||
|
||||
|
||||
//处理错误的统一方法 可以省去if err!=nil 这段代码
|
||||
func PanicError(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/eyebluecn/tank/code/tool/result"
|
||||
"go/build"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -9,7 +10,6 @@ import (
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"tank/code/tool/result"
|
||||
)
|
||||
|
||||
//判断文件或文件夹是否已经存在
|
||||
@ -43,14 +43,14 @@ func GetHomePath() string {
|
||||
//如果exPath中包含了 /private/var/folders 我们认为是在Mac的开发环境中
|
||||
macDev := strings.HasPrefix(exPath, "/private/var/folders")
|
||||
if macDev {
|
||||
exPath = GetGoPath() + "/src/tank/tmp"
|
||||
exPath = GetGoPath() + "/src/github.com/eyebluecn/tank/tmp"
|
||||
}
|
||||
|
||||
//如果exPath中包含了 \\AppData\\Local\\Temp 我们认为是在Win的开发环境中
|
||||
systemUser, err := user.Current()
|
||||
winDev := strings.HasPrefix(exPath, systemUser.HomeDir+"\\AppData\\Local\\Temp")
|
||||
if winDev {
|
||||
exPath = GetGoPath() + "/src/tank/tmp"
|
||||
exPath = GetGoPath() + "/src/github.com/eyebluecn/tank/tmp"
|
||||
}
|
||||
|
||||
return exPath
|
||||
|
Reference in New Issue
Block a user