From 7ceff43db6a11e426726ed1c66afcad44388f44b Mon Sep 17 00:00:00 2001 From: ysqi Date: Fri, 6 May 2016 13:26:48 +0800 Subject: [PATCH] Fixed error in window os --- parser.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/parser.go b/parser.go index fe719dce..3bf3cf6b 100644 --- a/parser.go +++ b/parser.go @@ -23,7 +23,6 @@ import ( "go/token" "io/ioutil" "os" - "path" "path/filepath" "sort" "strings" @@ -58,7 +57,8 @@ func init() { func parserPkg(pkgRealpath, pkgpath string) error { rep := strings.NewReplacer("\\", "_", "/", "_", ".", "_") - commentFilename = coomentPrefix + rep.Replace(strings.Replace(pkgRealpath, AppPath, "", -1)) + ".go" + commentFilename, _ = filepath.Rel(AppPath, pkgRealpath) + commentFilename = coomentPrefix + rep.Replace(commentFilename) + ".go" if !compareFile(pkgRealpath) { logs.Info(pkgRealpath + " no changed") return nil @@ -174,7 +174,7 @@ func genRouterCode(pkgRealpath string) { } } if globalinfo != "" { - f, err := os.Create(path.Join(getRouterDir(pkgRealpath), commentFilename)) + f, err := os.Create(filepath.Join(getRouterDir(pkgRealpath), commentFilename)) if err != nil { panic(err) } @@ -184,7 +184,7 @@ func genRouterCode(pkgRealpath string) { } func compareFile(pkgRealpath string) bool { - if !utils.FileExists(path.Join(getRouterDir(pkgRealpath), commentFilename)) { + if !utils.FileExists(filepath.Join(getRouterDir(pkgRealpath), commentFilename)) { return true } if utils.FileExists(lastupdateFilename) { @@ -235,11 +235,12 @@ func getpathTime(pkgRealpath string) (lastupdate int64, err error) { func getRouterDir(pkgRealpath string) string { dir := filepath.Dir(pkgRealpath) for { - d := path.Join(dir, "routers") - if dir == AppPath { + d := filepath.Join(dir, "routers") + if utils.FileExists(d) { return d } - if utils.FileExists(d) { + + if r, _ := filepath.Rel(dir, AppPath); r == "." { return d } // Parent dir.