1
0
mirror of https://github.com/astaxie/beego.git synced 2024-06-14 04:03:32 +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 appConfigPath string
// appConfigProvider is the provider for the config, default is ini // appConfigProvider is the provider for the config, default is ini
appConfigProvider = "ini" appConfigProvider = "ini"
// WorkPath is the absolute path to project root directory
WorkPath string
) )
func init() { func init() {
@ -137,7 +139,7 @@ func init() {
if AppPath, err = filepath.Abs(filepath.Dir(os.Args[0])); err != nil { if AppPath, err = filepath.Abs(filepath.Dir(os.Args[0])); err != nil {
panic(err) panic(err)
} }
workPath, err := os.Getwd() WorkPath, err = os.Getwd()
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -145,7 +147,7 @@ func init() {
if os.Getenv("BEEGO_RUNMODE") != "" { if os.Getenv("BEEGO_RUNMODE") != "" {
filename = os.Getenv("BEEGO_RUNMODE") + ".app.conf" filename = os.Getenv("BEEGO_RUNMODE") + ".app.conf"
} }
appConfigPath = filepath.Join(workPath, "conf", filename) appConfigPath = filepath.Join(WorkPath, "conf", filename)
if !utils.FileExists(appConfigPath) { if !utils.FileExists(appConfigPath) {
appConfigPath = filepath.Join(AppPath, "conf", filename) appConfigPath = filepath.Join(AppPath, "conf", filename)
if !utils.FileExists(appConfigPath) { if !utils.FileExists(appConfigPath) {

View File

@ -18,6 +18,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
"os"
"path" "path"
"path/filepath" "path/filepath"
"reflect" "reflect"
@ -249,25 +250,39 @@ func (p *ControllerRegister) addToRouter(method, pattern string, r *ControllerIn
func (p *ControllerRegister) Include(cList ...ControllerInterface) { func (p *ControllerRegister) Include(cList ...ControllerInterface) {
if BConfig.RunMode == DEV { if BConfig.RunMode == DEV {
skip := make(map[string]bool, 10) skip := make(map[string]bool, 10)
wgopath := utils.GetGOPATHs()
go111module := os.Getenv(`GO111MODULE`)
for _, c := range cList { for _, c := range cList {
reflectVal := reflect.ValueOf(c) reflectVal := reflect.ValueOf(c)
t := reflect.Indirect(reflectVal).Type() t := reflect.Indirect(reflectVal).Type()
wgopath := utils.GetGOPATHs() // for go modules
if len(wgopath) == 0 { if go111module == `on` {
panic("you are in dev mode. So please set gopath") pkgpath := filepath.Join(WorkPath, "..", t.PkgPath())
} if utils.FileExists(pkgpath) {
pkgpath := "" if pkgpath != "" {
for _, wg := range wgopath { if _, ok := skip[pkgpath]; !ok {
wg, _ = filepath.EvalSymlinks(filepath.Join(wg, "src", t.PkgPath())) skip[pkgpath] = true
if utils.FileExists(wg) { parserPkg(pkgpath, t.PkgPath())
pkgpath = wg }
break }
} }
} } else {
if pkgpath != "" { if len(wgopath) == 0 {
if _, ok := skip[pkgpath]; !ok { panic("you are in dev mode. So please set gopath")
skip[pkgpath] = true }
parserPkg(pkgpath, t.PkgPath()) 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())
}
} }
} }
} }