From 3daa0d26399ddddbaa7f706a461610fe875b2f02 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 24 Apr 2017 20:10:52 +0800 Subject: [PATCH 1/6] support go1.8 default gopath --- generate/swaggergen/g_docs.go | 9 +++++---- utils/utils.go | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index b68986d..a9f1c0a 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -36,6 +36,7 @@ import ( "github.com/astaxie/beego/swagger" "github.com/astaxie/beego/utils" beeLogger "github.com/beego/bee/logger" + bu "github.com/beego/bee/utils" ) const ( @@ -141,7 +142,7 @@ func parsePackageFromDir(path string) error { func GenerateDocs(curpath string) { fset := token.NewFileSet() - f, err := parser.ParseFile(fset, path.Join(curpath, "routers", "router.go"), nil, parser.ParseComments) + f, err := parser.ParseFile(fset, filepath.Join(curpath, "routers", "router.go"), nil, parser.ParseComments) if err != nil { beeLogger.Log.Fatalf("Error while parsing router.go: %s", err) } @@ -350,8 +351,8 @@ func analyseControllerPkg(vendorPath, localName, pkgpath string) { pps := strings.Split(pkgpath, "/") importlist[pps[len(pps)-1]] = pkgpath } - gopath := os.Getenv("GOPATH") - if gopath == "" { + gopaths := bu.GetGOPATHs() + if len(gopaths) == 0 { beeLogger.Log.Fatal("GOPATH environment variable is not set or empty") } pkgRealpath := "" @@ -360,7 +361,7 @@ func analyseControllerPkg(vendorPath, localName, pkgpath string) { if utils.FileExists(wg) { pkgRealpath = wg } else { - wgopath := filepath.SplitList(gopath) + wgopath := gopaths for _, wg := range wgopath { wg, _ = filepath.EvalSymlinks(filepath.Join(wg, "src", pkgpath)) if utils.FileExists(wg) { diff --git a/utils/utils.go b/utils/utils.go index e1fd20d..60b3d8a 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -52,6 +52,9 @@ func IsExist(path string) bool { // GetGOPATHs returns all paths in GOPATH variable. func GetGOPATHs() []string { gopath := os.Getenv("GOPATH") + if gopath == "" && strings.Compare(runtime.Version(), "go1.8") >= 0 { + gopath = defaultGOPATH() + } return filepath.SplitList(gopath) } @@ -61,7 +64,7 @@ func IsInGOPATH(thePath string) bool { thePath = filepath.ToSlash(thePath) } for _, gopath := range GetGOPATHs() { - if strings.Contains(thePath, gopath+"/src") { + if strings.Contains(thePath, filepath.Join(gopath, "src")) { return true } } @@ -425,3 +428,16 @@ func GetFileModTime(path string) int64 { return fi.ModTime().Unix() } + +func defaultGOPATH() string { + env := "HOME" + if runtime.GOOS == "windows" { + env = "USERPROFILE" + } else if runtime.GOOS == "plan9" { + env = "home" + } + if home := os.Getenv(env); home != "" { + return filepath.Join(home, "go") + } + return "" +} From 6afbafa2504d1c634b8bbff57f4dbd82335d9238 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 24 Apr 2017 20:51:56 +0800 Subject: [PATCH 2/6] Check Gopath in one place --- cmd/commands/version/version.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/commands/version/version.go b/cmd/commands/version/version.go index 596bcf5..0a9197d 100644 --- a/cmd/commands/version/version.go +++ b/cmd/commands/version/version.go @@ -17,6 +17,7 @@ import ( "github.com/beego/bee/cmd/commands" beeLogger "github.com/beego/bee/logger" "github.com/beego/bee/logger/colors" + "github.com/beego/bee/utils" "gopkg.in/yaml.v2" ) @@ -117,16 +118,15 @@ func ShowShortVersionBanner() { } func GetBeegoVersion() string { - gopath := os.Getenv("GOPATH") re, err := regexp.Compile(`VERSION = "([0-9.]+)"`) if err != nil { return "" } - if gopath == "" { + wgopath := utils.GetGOPATHs() + if len(wgopath) == 0 { beeLogger.Log.Error("You need to set GOPATH environment variable") return "" } - wgopath := path.SplitList(gopath) for _, wg := range wgopath { wg, _ = path.EvalSymlinks(path.Join(wg, "src", "github.com", "astaxie", "beego")) filename := path.Join(wg, "beego.go") From ffbe29ae2244da3ea29c25b0c95de74dfa51190b Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 24 Apr 2017 21:00:39 +0800 Subject: [PATCH 3/6] fix #2581 --- utils/utils.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index 60b3d8a..13e50b1 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -60,9 +60,6 @@ func GetGOPATHs() []string { // IsInGOPATH checks whether the path is inside of any GOPATH or not func IsInGOPATH(thePath string) bool { - if runtime.GOOS == "windows" { - thePath = filepath.ToSlash(thePath) - } for _, gopath := range GetGOPATHs() { if strings.Contains(thePath, filepath.Join(gopath, "src")) { return true From e84d6f9a9c73fb21c1f0960c748c891c12132d67 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 24 Apr 2017 21:06:31 +0800 Subject: [PATCH 4/6] use filepath to generate appcode --- generate/g_appcode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generate/g_appcode.go b/generate/g_appcode.go index 5444a89..fd6a3ed 100644 --- a/generate/g_appcode.go +++ b/generate/g_appcode.go @@ -863,7 +863,7 @@ func writeRouterFile(tables []*Table, rPath string, selectedTables map[string]bo nameSpaces = append(nameSpaces, nameSpace) } // Add export controller - fpath := path.Join(rPath, "router.go") + fpath := filepath.Join(rPath, "router.go") routerStr := strings.Replace(RouterTPL, "{{nameSpaces}}", strings.Join(nameSpaces, ""), 1) routerStr = strings.Replace(routerStr, "{{pkgPath}}", pkgPath, 1) var f *os.File From 963e1c9d058351f5f77cd9ec3140b5598770078a Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 24 Apr 2017 21:11:32 +0800 Subject: [PATCH 5/6] bee 1.8.3 --- cmd/commands/version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/commands/version/version.go b/cmd/commands/version/version.go index 0a9197d..b318c8e 100644 --- a/cmd/commands/version/version.go +++ b/cmd/commands/version/version.go @@ -57,7 +57,7 @@ Prints the current Bee, Beego and Go version alongside the platform information. } var outputFormat string -const version = "1.8.2" +const version = "1.8.3" func init() { fs := flag.NewFlagSet("version", flag.ContinueOnError) From 1cc7abaac6ff9d12decc4b8b731eb73a058be747 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 24 Apr 2017 21:45:27 +0800 Subject: [PATCH 6/6] fix gosimple --- cmd/commands/run/run.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/commands/run/run.go b/cmd/commands/run/run.go index 6820024..2010e5f 100644 --- a/cmd/commands/run/run.go +++ b/cmd/commands/run/run.go @@ -219,7 +219,6 @@ func readAppDirectories(directory string, paths *[]string) { useDirectory = true } } - return } // If a file is excluded