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:
parent
9069078ac0
commit
304e6cc0a4
39
apiapp.go
39
apiapp.go
@ -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
2
fix.go
@ -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
8
g.go
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
g_appcode.go
16
g_appcode.go
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// article
|
// article
|
||||||
|
18
g_docs.go
18
g_docs.go
@ -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)
|
||||||
|
@ -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) {
|
||||||
@ -30,7 +30,7 @@ func generateModel(mname, fields, crupath string) {
|
|||||||
defer f.Close()
|
defer f.Close()
|
||||||
var content string
|
var content string
|
||||||
if fields != "" {
|
if fields != "" {
|
||||||
generateStructure(modelName,fields,crupath)
|
generateStructure(modelName, fields, crupath)
|
||||||
content = strings.Replace(CRUD_MODEL_TPL, "{{packageName}}", packageName, -1)
|
content = strings.Replace(CRUD_MODEL_TPL, "{{packageName}}", packageName, -1)
|
||||||
pkgPath := getPackagePath(crupath)
|
pkgPath := getPackagePath(crupath)
|
||||||
content = strings.Replace(content, "{{pkgPath}}", pkgPath, -1)
|
content = strings.Replace(content, "{{pkgPath}}", pkgPath, -1)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// recipe
|
// recipe
|
||||||
|
10
migrate.go
10
migrate.go
@ -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 {
|
||||||
|
39
new.go
39
new.go
@ -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)
|
||||||
@ -87,42 +94,42 @@ func createApp(cmd *Command, args []string) int {
|
|||||||
ColorLog("[INFO] Creating application...\n")
|
ColorLog("[INFO] Creating application...\n")
|
||||||
|
|
||||||
os.MkdirAll(apppath, 0755)
|
os.MkdirAll(apppath, 0755)
|
||||||
fmt.Println("\tcreate\t", apppath + string(path.Separator))
|
fmt.Println("\tcreate\t", apppath+string(path.Separator))
|
||||||
|
|
||||||
os.Mkdir(path.Join(apppath, "conf"), 0755)
|
os.Mkdir(path.Join(apppath, "conf"), 0755)
|
||||||
fmt.Println("\tcreate\t", path.Join(apppath, "conf") + string(path.Separator))
|
fmt.Println("\tcreate\t", path.Join(apppath, "conf")+string(path.Separator))
|
||||||
|
|
||||||
os.Mkdir(path.Join(apppath, "controllers"), 0755)
|
os.Mkdir(path.Join(apppath, "controllers"), 0755)
|
||||||
fmt.Println("\tcreate\t", path.Join(apppath, "controllers") + string(path.Separator))
|
fmt.Println("\tcreate\t", path.Join(apppath, "controllers")+string(path.Separator))
|
||||||
|
|
||||||
os.Mkdir(path.Join(apppath, "helpers"), 0755)
|
os.Mkdir(path.Join(apppath, "helpers"), 0755)
|
||||||
fmt.Println("\tcreate\t", path.Join(apppath, "helpers") + string(path.Separator))
|
fmt.Println("\tcreate\t", path.Join(apppath, "helpers")+string(path.Separator))
|
||||||
|
|
||||||
os.Mkdir(path.Join(apppath, "models"), 0755)
|
os.Mkdir(path.Join(apppath, "models"), 0755)
|
||||||
fmt.Println("\tcreate\t", path.Join(apppath, "models") + string(path.Separator))
|
fmt.Println("\tcreate\t", path.Join(apppath, "models")+string(path.Separator))
|
||||||
|
|
||||||
os.Mkdir(path.Join(apppath, "routers"), 0755)
|
os.Mkdir(path.Join(apppath, "routers"), 0755)
|
||||||
fmt.Println("\tcreate\t", path.Join(apppath, "routers") + string(path.Separator))
|
fmt.Println("\tcreate\t", path.Join(apppath, "routers")+string(path.Separator))
|
||||||
|
|
||||||
os.Mkdir(path.Join(apppath, "tests"), 0755)
|
os.Mkdir(path.Join(apppath, "tests"), 0755)
|
||||||
fmt.Println("\tcreate\t", path.Join(apppath, "tests") + string(path.Separator))
|
fmt.Println("\tcreate\t", path.Join(apppath, "tests")+string(path.Separator))
|
||||||
|
|
||||||
os.Mkdir(path.Join(apppath, "structures"), 0755)
|
os.Mkdir(path.Join(apppath, "structures"), 0755)
|
||||||
fmt.Println("\tcreate\t", path.Join(apppath, "structures") + string(path.Separator))
|
fmt.Println("\tcreate\t", path.Join(apppath, "structures")+string(path.Separator))
|
||||||
|
|
||||||
os.Mkdir(path.Join(apppath, "static"), 0755)
|
os.Mkdir(path.Join(apppath, "static"), 0755)
|
||||||
fmt.Println("\tcreate\t", path.Join(apppath, "static") + string(path.Separator))
|
fmt.Println("\tcreate\t", path.Join(apppath, "static")+string(path.Separator))
|
||||||
|
|
||||||
os.Mkdir(path.Join(apppath, "static", "js"), 0755)
|
os.Mkdir(path.Join(apppath, "static", "js"), 0755)
|
||||||
fmt.Println("\tcreate\t", path.Join(apppath, "static", "js") + string(path.Separator))
|
fmt.Println("\tcreate\t", path.Join(apppath, "static", "js")+string(path.Separator))
|
||||||
|
|
||||||
os.Mkdir(path.Join(apppath, "static", "css"), 0755)
|
os.Mkdir(path.Join(apppath, "static", "css"), 0755)
|
||||||
fmt.Println("\tcreate\t", path.Join(apppath, "static", "css") + string(path.Separator))
|
fmt.Println("\tcreate\t", path.Join(apppath, "static", "css")+string(path.Separator))
|
||||||
|
|
||||||
os.Mkdir(path.Join(apppath, "static", "img"), 0755)
|
os.Mkdir(path.Join(apppath, "static", "img"), 0755)
|
||||||
fmt.Println("\tcreate\t", path.Join(apppath, "static", "img") + string(path.Separator))
|
fmt.Println("\tcreate\t", path.Join(apppath, "static", "img")+string(path.Separator))
|
||||||
|
|
||||||
fmt.Println("\tcreate\t", path.Join(apppath, "views") + string(path.Separator))
|
fmt.Println("\tcreate\t", path.Join(apppath, "views")+string(path.Separator))
|
||||||
|
|
||||||
os.Mkdir(path.Join(apppath, "views"), 0755)
|
os.Mkdir(path.Join(apppath, "views"), 0755)
|
||||||
fmt.Println("\tcreate\t", path.Join(apppath, "conf", "app.conf"))
|
fmt.Println("\tcreate\t", path.Join(apppath, "conf", "app.conf"))
|
||||||
|
@ -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 = `______
|
||||||
`______
|
|
||||||
| ___ \
|
| ___ \
|
||||||
| |_/ / ___ ___
|
| |_/ / ___ ___
|
||||||
| ___ \ / _ \ / _ \
|
| ___ \ / _ \ / _ \
|
||||||
|
Loading…
Reference in New Issue
Block a user