diff --git a/g/os/gfile/gfile.go b/g/os/gfile/gfile.go index 1a97a51dc..224b40bd0 100644 --- a/g/os/gfile/gfile.go +++ b/g/os/gfile/gfile.go @@ -5,8 +5,6 @@ // You can obtain one at https://github.com/gogf/gf. // Package gfile provides easy-to-use operations for file system. -// -// 文件管理. package gfile import ( @@ -15,6 +13,7 @@ import ( "fmt" "github.com/gogf/gf/g/container/gtype" "github.com/gogf/gf/g/text/gregex" + "github.com/gogf/gf/g/text/gstr" "github.com/gogf/gf/g/util/gconv" "io" "os" @@ -452,11 +451,21 @@ func MainPkgPath() string { } for i := 1; i < 10000; i++ { if _, file, _, ok := runtime.Caller(i); ok { - if gregex.IsMatchString(`package\s+main`, GetContents(file)) { - path = Dir(file) - mainPkgPath.Set(path) - return path + if gstr.Contains(file, "/gf/g/") { + continue } + path = file + for path != "/" && gstr.Contains(path, "/") { + files, _ := ScanDir(path, "*.go") + for _, v := range files { + if gregex.IsMatchString(`package\s+main`, GetContents(v)) { + mainPkgPath.Set(path) + return path + } + } + path = Dir(path) + } + } else { break } diff --git a/geg/other/test.go b/geg/other/test.go index 03407626f..47632c222 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -3,10 +3,16 @@ package main import ( "fmt" "github.com/gogf/gf/g" + "github.com/gogf/gf/g/os/gfile" "github.com/gogf/gf/g/util/gconv" ) func main() { + fmt.Println(gfile.Dir("/")) + return + a := []int{1,2,3} + fmt.Println(a[:0]) + return type Person struct{ Name string }