From 99f8aafc9429632cbbe4338d08b5c16a7064fa13 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 10 Nov 2018 12:31:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8windows=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E4=B8=8B=E7=9A=84gfile.MainPkgPath=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/os/gfile/gfile.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/g/os/gfile/gfile.go b/g/os/gfile/gfile.go index ad6513666..b5c3e0ec5 100644 --- a/g/os/gfile/gfile.go +++ b/g/os/gfile/gfile.go @@ -14,6 +14,7 @@ import ( "gitee.com/johng/gf/g/container/gtype" "gitee.com/johng/gf/g/util/gconv" "gitee.com/johng/gf/g/util/gregex" + "gitee.com/johng/gf/g/util/gstr" "io" "os" "os/exec" @@ -379,6 +380,10 @@ func MainPkgPath() string { } f := "" goroot := runtime.GOROOT() + // runtime.GOROOT() 在windows下有可能是以'\'符号分隔, + // 而 runtime.Caller(i) 获取到的文件路径却是以'/'符号分隔, + // 因此这里统一转换为'/'符号再进行比较 + goroot = gstr.Replace(goroot, "\\", "/") for i := 1; i < 10000; i++ { if _, file, _, ok := runtime.Caller(i); ok { // 不包含go源码路径