1
0
mirror of https://github.com/beego/bee.git synced 2024-11-23 06:40:54 +00:00

Fixed double GOPATH issue

Default Crawl GOPATH full path
So we will achieve complete double GOPATH
Ex: / XXX: / CCCC
But just need to pick up: / CCCC
This commit is contained in:
Dylan 2016-07-11 18:35:35 +08:00
parent 9069078ac0
commit 304e6cc0a4
11 changed files with 92 additions and 56 deletions

View File

@ -632,16 +632,18 @@ func createapi(cmd *Command, args []string) int {
} else { } else {
os.Mkdir(path.Join(apppath, "models"), 0755) os.Mkdir(path.Join(apppath, "models"), 0755)
fmt.Println("\tcreate\t", path.Join(apppath, "models")) fmt.Println("\tcreate\t", path.Join(apppath, "models"))
os.Mkdir(path.Join(apppath, "routers"), 0755)
fmt.Println("create routers:", path.Join(apppath, "routers"))
os.Mkdir(path.Join(apppath, "structures"), 0755)
fmt.Println("create structures:", path.Join(apppath, "structures"))
fmt.Println("create controllers object_controller.go:", path.Join(apppath, "controllers", "object_controller.go")) os.Mkdir(path.Join(apppath, "routers"), 0755)
fmt.Println("\tcreate\t", path.Join(apppath, "routers"))
os.Mkdir(path.Join(apppath, "structures"), 0755)
fmt.Println("\tcreate\t", path.Join(apppath, "structures"))
fmt.Println("\tcreate\t", path.Join(apppath, "controllers", "object_controller.go"))
WriteToFile(path.Join(apppath, "controllers", "object_controller.go"), WriteToFile(path.Join(apppath, "controllers", "object_controller.go"),
strings.Replace(apiControllers, "{{.Appname}}", packpath, -1)) strings.Replace(apiControllers, "{{.Appname}}", packpath, -1))
fmt.Println("create controllers user_controller.go:", path.Join(apppath, "controllers", "user_controller.go")) fmt.Println("\tcreate\t", path.Join(apppath, "controllers", "user_controller.go"))
WriteToFile(path.Join(apppath, "controllers", "user_controller.go"), WriteToFile(path.Join(apppath, "controllers", "user_controller.go"),
strings.Replace(apiControllers2, "{{.Appname}}", packpath, -1)) strings.Replace(apiControllers2, "{{.Appname}}", packpath, -1))
@ -653,24 +655,24 @@ func createapi(cmd *Command, args []string) int {
WriteToFile(path.Join(apppath, "routers", "router.go"), WriteToFile(path.Join(apppath, "routers", "router.go"),
strings.Replace(apirouter, "{{.Appname}}", packpath, -1)) strings.Replace(apirouter, "{{.Appname}}", packpath, -1))
fmt.Println("create models object.go:", path.Join(apppath, "models", "object.go")) fmt.Println("\tcreate\t", path.Join(apppath, "models", "object.go"))
WriteToFile(path.Join(apppath, "models", "object.go"), WriteToFile(path.Join(apppath, "models", "object.go"),
strings.Replace(apiModels, "{{.Appname}}", packpath, -1)) strings.Replace(apiModels, "{{.Appname}}", packpath, -1))
fmt.Println("create models user.go:", path.Join(apppath, "models", "user.go")) fmt.Println("\tcreate\t", path.Join(apppath, "models", "user.go"))
WriteToFile(path.Join(apppath, "models", "user.go"), WriteToFile(path.Join(apppath, "models", "user.go"),
strings.Replace(apiModels2, "{{.Appname}}", packpath, -1)) strings.Replace(apiModels2, "{{.Appname}}", packpath, -1))
fmt.Println("create structures user_structure.go:", path.Join(apppath, "structures", "user_structure.go")) fmt.Println("\tcreate\t", path.Join(apppath, "structures", "user_structure.go"))
WriteToFile(path.Join(apppath, "structures", "user_structure.go"), apistructures) WriteToFile(path.Join(apppath, "structures", "user_structure.go"), apistructures)
fmt.Println("create structures object_structure.go:", path.Join(apppath, "structures", "object_structure.go")) fmt.Println("\tcreate\t", path.Join(apppath, "structures", "object_structure.go"))
WriteToFile(path.Join(apppath, "structures", "object_structure.go"), apistructures2) WriteToFile(path.Join(apppath, "structures", "object_structure.go"), apistructures2)
fmt.Println("create helpers user_helper.go:", path.Join(apppath, "helpers", "user_helper.go")) fmt.Println("\tcreate\t", path.Join(apppath, "helpers", "user_helper.go"))
WriteToFile(path.Join(apppath, "helpers", "user_helper.go"), "package helpers") WriteToFile(path.Join(apppath, "helpers", "user_helper.go"), "package helpers")
fmt.Println("create helpers object_helper.go:", path.Join(apppath, "helpers", "object_helper.go")) fmt.Println("\tcreate\t", path.Join(apppath, "helpers", "object_helper.go"))
WriteToFile(path.Join(apppath, "helpers", "object_helper.go"), "package helpers") WriteToFile(path.Join(apppath, "helpers", "object_helper.go"), "package helpers")
fmt.Println("\tcreate\t", path.Join(apppath, "docs", "doc.go")) fmt.Println("\tcreate\t", path.Join(apppath, "docs", "doc.go"))
@ -685,9 +687,16 @@ func createapi(cmd *Command, args []string) int {
} }
func checkEnv(appname string) (apppath, packpath string, err error) { func checkEnv(appname string) (apppath, packpath string, err error) {
gopath := os.Getenv("GOPATH") gopaths := GetGOPATHs()
Debugf("gopath:%s", gopath) Debugf("gopath:%s", gopaths)
if gopath == "" { gopath := ""
switch len(gopaths) {
case 1:
gopath = gopaths[0]
case 2:
gopath = gopaths[1]
default:
err = fmt.Errorf("you should set GOPATH in the env") err = fmt.Errorf("you should set GOPATH in the env")
return return
} }

2
fix.go
View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"go/parser" "go/parser"
"go/token" "go/token"
"io/ioutil" "io/ioutil"
@ -8,7 +9,6 @@ import (
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
"fmt"
) )
var cmdFix = &Command{ var cmdFix = &Command{

8
g.go
View File

@ -94,11 +94,11 @@ func generateCode(cmd *Command, args []string) int {
os.Exit(2) os.Exit(2)
} }
gopath := os.Getenv("GOPATH") gopaths := GetGOPATHs()
Debugf("gopath:%s", gopath) Debugf("gopath:%s", gopaths)
if gopath == "" { if len(gopaths) == 0 {
ColorLog("[ERRO] $GOPATH not found\n") ColorLog("[ERRO] $GOPATH not found\n")
ColorLog("[HINT] Set $GOPATH in your environment vairables\n") ColorLog("[HINT] Set $GOPATH in your environment variables\n")
os.Exit(2) os.Exit(2)
} }

View File

@ -1030,10 +1030,18 @@ func getFileName(tbName string) (filename string) {
} }
func getPackagePath(curpath string) (packpath string) { func getPackagePath(curpath string) (packpath string) {
gopath := os.Getenv("GOPATH") gopaths := GetGOPATHs()
Debugf("gopath:%s", gopath) Debugf("gopath:%s", gopaths)
if gopath == "" { gopath := ""
ColorLog("[ERRO] you should set GOPATH in the env")
switch len(gopaths) {
case 1:
gopath = gopaths[0]
case 2:
gopath = gopaths[1]
default:
ColorLog("[ERRO] $GOPATH not found\n")
ColorLog("[HINT] Set $GOPATH in your environment variables\n")
os.Exit(2) os.Exit(2)
} }

View File

@ -15,10 +15,10 @@
package main package main
import ( import (
"fmt"
"os" "os"
"path" "path"
"strings" "strings"
"fmt"
) )
// article // article

View File

@ -276,10 +276,22 @@ func analisyscontrollerPkg(localName, pkgpath string) {
if pkgpath == "github.com/astaxie/beego" { if pkgpath == "github.com/astaxie/beego" {
return return
} }
gopath := os.Getenv("GOPATH")
if gopath == "" { gopaths := GetGOPATHs()
panic("please set gopath") Debugf("gopath:%s", gopaths)
gopath := ""
switch len(gopaths) {
case 1:
gopath = gopaths[0]
case 2:
gopath = gopaths[1]
default:
ColorLog("[ERRO] $GOPATH not found\n")
ColorLog("[HINT] Set $GOPATH in your environment variables\n")
os.Exit(2)
} }
pkgRealpath := "" pkgRealpath := ""
wgopath := filepath.SplitList(gopath) wgopath := filepath.SplitList(gopath)

View File

@ -1,10 +1,10 @@
package main package main
import ( import (
"fmt"
"os" "os"
"path" "path"
"strings" "strings"
"fmt"
) )
func generateModel(mname, fields, crupath string) { func generateModel(mname, fields, crupath string) {

View File

@ -1,9 +1,9 @@
package main package main
import ( import (
"fmt"
"os" "os"
"path" "path"
"fmt"
) )
// recipe // recipe

View File

@ -66,13 +66,15 @@ func runMigration(cmd *Command, args []string) int {
crupath, _ := os.Getwd() crupath, _ := os.Getwd()
gopath := os.Getenv("GOPATH") gopaths := GetGOPATHs()
Debugf("gopath:%s", gopath) Debugf("gopath:%s", gopaths)
if gopath == "" {
if len(gopaths) == 0 {
ColorLog("[ERRO] $GOPATH not found\n") ColorLog("[ERRO] $GOPATH not found\n")
ColorLog("[HINT] Set $GOPATH in your environment vairables\n") ColorLog("[HINT] Set $GOPATH in your environment variables\n")
os.Exit(2) os.Exit(2)
} }
// load config // load config
err := loadConfig() err := loadConfig()
if err != nil { if err != nil {

13
new.go
View File

@ -65,9 +65,16 @@ func createApp(cmd *Command, args []string) int {
os.Exit(2) os.Exit(2)
} }
gopath := os.Getenv("GOPATH") gopaths := GetGOPATHs()
Debugf("gopath:%s", gopath) Debugf("gopath:%s", gopaths)
if gopath == "" { gopath := ""
switch len(gopaths) {
case 1:
gopath = gopaths[0]
case 2:
gopath = gopaths[1]
default:
ColorLog("[ERRO] $GOPATH not found\n") ColorLog("[ERRO] $GOPATH not found\n")
ColorLog("[HINT] Set $GOPATH in your environment variables\n") ColorLog("[HINT] Set $GOPATH in your environment variables\n")
os.Exit(2) os.Exit(2)

View File

@ -2,12 +2,12 @@ package main
import ( import (
"bufio" "bufio"
"bytes"
"fmt" "fmt"
"io" "io"
"os" "os"
path "path/filepath" path "path/filepath"
"regexp" "regexp"
"bytes"
) )
var cmdVersion = &Command{ var cmdVersion = &Command{
@ -24,8 +24,7 @@ bee version
`, `,
} }
const verboseVersionBanner = const verboseVersionBanner = `______
`______
| ___ \ | ___ \
| |_/ / ___ ___ | |_/ / ___ ___
| ___ \ / _ \ / _ \ | ___ \ / _ \ / _ \
@ -43,8 +42,7 @@ Compiler : {{ .Compiler }}
Date : {{ Now "Monday, 2 Jan 2006" }} Date : {{ Now "Monday, 2 Jan 2006" }}
` `
const shortVersionBanner = const shortVersionBanner = `______
`______
| ___ \ | ___ \
| |_/ / ___ ___ | |_/ / ___ ___
| ___ \ / _ \ / _ \ | ___ \ / _ \ / _ \