From 0cffaf8ea6629fc662962b473b413cca9842d249 Mon Sep 17 00:00:00 2001 From: Gero Nimo Date: Fri, 24 Mar 2017 04:54:17 -0300 Subject: [PATCH] Fix generate swagger model api doc on Windows. Add multiple gopath support for ParsePackagesFromDir. Improves gloomyzerg@39cc0bc04e109ff0f69e73d567354d9e82b7c24c fix for #332 that got lost on some merge. --- main.go | 3 +-- utils/utils.go | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index d9401dc..beccb06 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,6 @@ import ( "flag" "log" "os" - "strings" "github.com/beego/bee/cmd" "github.com/beego/bee/cmd/commands" @@ -64,7 +63,7 @@ func main() { // Check if current directory is inside the GOPATH, // if so parse the packages inside it. - if strings.Contains(currentpath, utils.GetGOPATHs()[0]+"/src") && cmd.IfGenerateDocs(c.Name(), args) { + if utils.IsInGOPATH(currentpath) && cmd.IfGenerateDocs(c.Name(), args) { swaggergen.ParsePackagesFromDir(currentpath) } diff --git a/utils/utils.go b/utils/utils.go index b41de0a..5224c1b 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -61,12 +61,17 @@ func GetGOPATHs() []string { return paths } -// IsInGOPATH checks the path is in the fisrt GOPATH(/src) or not +// 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) } - return strings.Contains(thePath, GetGOPATHs()[0]+"/src") + for _, gopath := range GetGOPATHs() { + if strings.Contains(thePath, gopath + "/src") { + return true + } + } + return false } // IsBeegoProject checks whether the current path is a Beego application or not