mirror of
https://github.com/astaxie/beego.git
synced 2025-08-31 00:57:32 +00:00
Merge pull request #3998 from guhan121/go_modules_route_compatibility
for go modules, generate route by `GO111MODULE=on`
This commit is contained in:
45
router.go
45
router.go
@@ -18,6 +18,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@@ -253,25 +254,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())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user