1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 09:40:56 +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,10 +250,23 @@ 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()
// 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())
}
}
}
} else {
if len(wgopath) == 0 {
panic("you are in dev mode. So please set gopath")
}
@ -272,6 +286,7 @@ func (p *ControllerRegister) Include(cList ...ControllerInterface) {
}
}
}
}
for _, c := range cList {
reflectVal := reflect.ValueOf(c)
t := reflect.Indirect(reflectVal).Type()