Fixed error in window os

This commit is contained in:
ysqi 2016-05-06 13:26:48 +08:00
parent 3c8ed9adfc
commit 7ceff43db6
1 changed files with 8 additions and 7 deletions

View File

@ -23,7 +23,6 @@ import (
"go/token" "go/token"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"path/filepath" "path/filepath"
"sort" "sort"
"strings" "strings"
@ -58,7 +57,8 @@ func init() {
func parserPkg(pkgRealpath, pkgpath string) error { func parserPkg(pkgRealpath, pkgpath string) error {
rep := strings.NewReplacer("\\", "_", "/", "_", ".", "_") 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) { if !compareFile(pkgRealpath) {
logs.Info(pkgRealpath + " no changed") logs.Info(pkgRealpath + " no changed")
return nil return nil
@ -174,7 +174,7 @@ func genRouterCode(pkgRealpath string) {
} }
} }
if globalinfo != "" { if globalinfo != "" {
f, err := os.Create(path.Join(getRouterDir(pkgRealpath), commentFilename)) f, err := os.Create(filepath.Join(getRouterDir(pkgRealpath), commentFilename))
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -184,7 +184,7 @@ func genRouterCode(pkgRealpath string) {
} }
func compareFile(pkgRealpath string) bool { func compareFile(pkgRealpath string) bool {
if !utils.FileExists(path.Join(getRouterDir(pkgRealpath), commentFilename)) { if !utils.FileExists(filepath.Join(getRouterDir(pkgRealpath), commentFilename)) {
return true return true
} }
if utils.FileExists(lastupdateFilename) { if utils.FileExists(lastupdateFilename) {
@ -235,11 +235,12 @@ func getpathTime(pkgRealpath string) (lastupdate int64, err error) {
func getRouterDir(pkgRealpath string) string { func getRouterDir(pkgRealpath string) string {
dir := filepath.Dir(pkgRealpath) dir := filepath.Dir(pkgRealpath)
for { for {
d := path.Join(dir, "routers") d := filepath.Join(dir, "routers")
if dir == AppPath { if utils.FileExists(d) {
return d return d
} }
if utils.FileExists(d) {
if r, _ := filepath.Rel(dir, AppPath); r == "." {
return d return d
} }
// Parent dir. // Parent dir.