1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-22 22:50:50 +00:00

for go modules, generate route by GO111MODULE=on

This commit is contained in:
qiantao 2020-05-22 11:35:45 +08:00
parent 8f3d1c5f42
commit 4ffe26a1d2
2 changed files with 34 additions and 17 deletions

View File

@ -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) {

View File

@ -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())
}
}
}
}