diff --git a/common/utils.go b/common/utils.go index 1f86e05..d93fea1 100644 --- a/common/utils.go +++ b/common/utils.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "runtime" + "strings" "time" "github.com/gin-gonic/gin" @@ -71,5 +72,9 @@ func MustGetwd() string { // GetCurrentCodeDir 获取当前源代码的目录,主要用于测试时,查找相关文件 func GetCurrentCodeDir() string { _, file, _, _ := runtime.Caller(1) - return filepath.Dir(file) + wd := MustGetwd() + if strings.HasSuffix(wd, "/test") { + wd = filepath.Dir(wd) + } + return wd + "/" + filepath.Base(filepath.Dir(file)) }