diff --git a/config.go b/config.go index 7969dcea..42e4669e 100644 --- a/config.go +++ b/config.go @@ -129,6 +129,8 @@ var ( appConfigPath string // appConfigProvider is the provider for the config, default is ini appConfigProvider = "ini" + // WorkPath is the absolute path to project root directory + WorkPath string ) func init() { @@ -137,7 +139,7 @@ func init() { if AppPath, err = filepath.Abs(filepath.Dir(os.Args[0])); err != nil { panic(err) } - workPath, err := os.Getwd() + WorkPath, err = os.Getwd() if err != nil { panic(err) } @@ -145,7 +147,7 @@ func init() { if os.Getenv("BEEGO_RUNMODE") != "" { filename = os.Getenv("BEEGO_RUNMODE") + ".app.conf" } - appConfigPath = filepath.Join(workPath, "conf", filename) + appConfigPath = filepath.Join(WorkPath, "conf", filename) if !utils.FileExists(appConfigPath) { appConfigPath = filepath.Join(AppPath, "conf", filename) if !utils.FileExists(appConfigPath) { diff --git a/router.go b/router.go index e71366b4..064e96ab 100644 --- a/router.go +++ b/router.go @@ -18,6 +18,7 @@ import ( "errors" "fmt" "net/http" + "os" "path" "path/filepath" "reflect" @@ -249,25 +250,39 @@ func (p *ControllerRegister) addToRouter(method, pattern string, r *ControllerIn func (p *ControllerRegister) Include(cList ...ControllerInterface) { if BConfig.RunMode == DEV { skip := make(map[string]bool, 10) + wgopath := utils.GetGOPATHs() + go111module := os.Getenv(`GO111MODULE`) for _, c := range cList { reflectVal := reflect.ValueOf(c) t := reflect.Indirect(reflectVal).Type() - wgopath := utils.GetGOPATHs() - if len(wgopath) == 0 { - panic("you are in dev mode. So please set gopath") - } - pkgpath := "" - for _, wg := range wgopath { - wg, _ = filepath.EvalSymlinks(filepath.Join(wg, "src", t.PkgPath())) - if utils.FileExists(wg) { - pkgpath = wg - break + // for go modules + if go111module == `on` { + pkgpath := filepath.Join(WorkPath, "..", t.PkgPath()) + if utils.FileExists(pkgpath) { + if pkgpath != "" { + if _, ok := skip[pkgpath]; !ok { + skip[pkgpath] = true + parserPkg(pkgpath, t.PkgPath()) + } + } } - } - if pkgpath != "" { - if _, ok := skip[pkgpath]; !ok { - skip[pkgpath] = true - parserPkg(pkgpath, t.PkgPath()) + } else { + if len(wgopath) == 0 { + panic("you are in dev mode. So please set gopath") + } + pkgpath := "" + for _, wg := range wgopath { + wg, _ = filepath.EvalSymlinks(filepath.Join(wg, "src", t.PkgPath())) + if utils.FileExists(wg) { + pkgpath = wg + break + } + } + if pkgpath != "" { + if _, ok := skip[pkgpath]; !ok { + skip[pkgpath] = true + parserPkg(pkgpath, t.PkgPath()) + } } } }