mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 19:00:54 +00:00
support Go1.8 default GOPATH
This commit is contained in:
parent
3bb4ca5adc
commit
52f916a28a
@ -17,7 +17,6 @@ package beego
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -219,13 +218,11 @@ func (p *ControllerRegister) Include(cList ...ControllerInterface) {
|
|||||||
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()
|
||||||
gopath := os.Getenv("GOPATH")
|
wgopath := utils.GetGOPATHs()
|
||||||
if gopath == "" {
|
if len(wgopath) == 0 {
|
||||||
panic("you are in dev mode. So please set gopath")
|
panic("you are in dev mode. So please set gopath")
|
||||||
}
|
}
|
||||||
pkgpath := ""
|
pkgpath := ""
|
||||||
|
|
||||||
wgopath := filepath.SplitList(gopath)
|
|
||||||
for _, wg := range wgopath {
|
for _, wg := range wgopath {
|
||||||
wg, _ = filepath.EvalSymlinks(filepath.Join(wg, "src", t.PkgPath()))
|
wg, _ = filepath.EvalSymlinks(filepath.Join(wg, "src", t.PkgPath()))
|
||||||
if utils.FileExists(wg) {
|
if utils.FileExists(wg) {
|
||||||
|
30
utils/utils.go
Normal file
30
utils/utils.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetGOPATHs returns all paths in GOPATH variable.
|
||||||
|
func GetGOPATHs() []string {
|
||||||
|
gopath := os.Getenv("GOPATH")
|
||||||
|
if gopath == "" && strings.Compare(runtime.Version(), "go1.8") >= 0 {
|
||||||
|
gopath = defaultGOPATH()
|
||||||
|
}
|
||||||
|
return filepath.SplitList(gopath)
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultGOPATH() string {
|
||||||
|
env := "HOME"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
env = "USERPROFILE"
|
||||||
|
} else if runtime.GOOS == "plan9" {
|
||||||
|
env = "home"
|
||||||
|
}
|
||||||
|
if home := os.Getenv(env); home != "" {
|
||||||
|
return filepath.Join(home, "go")
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user