From c6141fb671ff6f007525cf20e413cbe26a2ca54f Mon Sep 17 00:00:00 2001 From: Back Date: Wed, 24 Aug 2016 19:23:29 +0800 Subject: [PATCH 1/2] Update g_appcode.go If use symlink to define GOPATH, bee generate won't work . Example: ``` shell ln -s /mnt/go/ /go/ export GOPATH=/go cd /go/src bee api hello_api cd /go/src/hello_api bee generate appcode -driver=mysql -level=1 -conn='xxx@xxx' > [ERRO] Can't generate application code outside of GOPATH '/go' ``` In g_appcode.go(line 985), using a EvalSymlinks, and got wg = "/mnt/go", but curpath = "/go/src/hello_api" now, that causing the bug. When using "bee" tool in GOPATH but echo "code is outside of GOPATH" --- g_appcode.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/g_appcode.go b/g_appcode.go index 76d78ad..95c3fae 100644 --- a/g_appcode.go +++ b/g_appcode.go @@ -983,6 +983,14 @@ func getPackagePath(curpath string) (packpath string) { wgopath := filepath.SplitList(gopath) for _, wg := range wgopath { + //Maybe is a path + if filepath.HasPrefix(strings.ToLower(curpath), strings.ToLower(wg)) { + haspath = true + appsrcpath = wg + break + } + + //Maybe is a symlink wg, _ = filepath.EvalSymlinks(path.Join(wg, "src")) if filepath.HasPrefix(strings.ToLower(curpath), strings.ToLower(wg)) { From 866fea3504e94ecbac76169d655de0ba7bfcdce9 Mon Sep 17 00:00:00 2001 From: Back Date: Wed, 24 Aug 2016 19:58:55 +0800 Subject: [PATCH 2/2] Fix compare symlink to path Now will compare path with path, symlink with symlink. --- g_appcode.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/g_appcode.go b/g_appcode.go index 95c3fae..03f53f0 100644 --- a/g_appcode.go +++ b/g_appcode.go @@ -992,8 +992,8 @@ func getPackagePath(curpath string) (packpath string) { //Maybe is a symlink wg, _ = filepath.EvalSymlinks(path.Join(wg, "src")) - - if filepath.HasPrefix(strings.ToLower(curpath), strings.ToLower(wg)) { + cur,_ := filepath.EvalSymlinks(curpath) + if filepath.HasPrefix(strings.ToLower(cur), strings.ToLower(wg)) { haspath = true appsrcpath = wg break