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

Merge pull request #687 from guhan121/develop0711

更好的检查go mod 方式;生成的go.mod 忽略Minor version
This commit is contained in:
askuy 2020-07-16 23:12:49 +08:00 committed by GitHub
commit c37857ed01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 9 deletions

View File

@ -19,7 +19,6 @@ import (
"github.com/beego/bee/logger/colors" "github.com/beego/bee/logger/colors"
"os" "os"
path "path/filepath" path "path/filepath"
"runtime"
"strings" "strings"
"github.com/beego/bee/cmd/commands" "github.com/beego/bee/cmd/commands"
@ -608,7 +607,7 @@ func createAPI(cmd *commands.Command, args []string) int {
os.MkdirAll(appPath, 0755) os.MkdirAll(appPath, 0755)
if module == `true` { //generate first for calc model name if module == `true` { //generate first for calc model name
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "go.mod"), "\x1b[0m") fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "go.mod"), "\x1b[0m")
utils.WriteToFile(path.Join(appPath, "go.mod"), fmt.Sprintf(goMod, packPath, runtime.Version()[2:], beegoVersion.String())) utils.WriteToFile(path.Join(appPath, "go.mod"), fmt.Sprintf(goMod, packPath, utils.GetGoVersionSkipMinor(), beegoVersion.String()))
} }
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", appPath, "\x1b[0m") fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", appPath, "\x1b[0m")
os.Mkdir(path.Join(appPath, "conf"), 0755) os.Mkdir(path.Join(appPath, "conf"), 0755)

View File

@ -1,11 +1,9 @@
package hprose package hprose
import ( import (
"fmt"
"github.com/beego/bee/logger/colors" "github.com/beego/bee/logger/colors"
"os" "os"
"runtime"
"fmt"
"path" "path"
"strings" "strings"
@ -113,7 +111,7 @@ func createhprose(cmd *commands.Command, args []string) int {
os.MkdirAll(apppath, 0755) os.MkdirAll(apppath, 0755)
if module == `true` { //generate first for calc model name if module == `true` { //generate first for calc model name
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "go.mod"), "\x1b[0m") fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "go.mod"), "\x1b[0m")
utils.WriteToFile(path.Join(apppath, "go.mod"), fmt.Sprintf(goMod, packpath, runtime.Version()[2:], beegoVersion.String())) utils.WriteToFile(path.Join(apppath, "go.mod"), fmt.Sprintf(goMod, packpath, utils.GetGoVersionSkipMinor(), beegoVersion.String()))
} }
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", apppath, "\x1b[0m") fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", apppath, "\x1b[0m")
os.Mkdir(path.Join(apppath, "conf"), 0755) os.Mkdir(path.Join(apppath, "conf"), 0755)

View File

@ -18,7 +18,6 @@ import (
"fmt" "fmt"
"os" "os"
path "path/filepath" path "path/filepath"
"runtime"
"strings" "strings"
"github.com/beego/bee/cmd/commands" "github.com/beego/bee/cmd/commands"
@ -305,7 +304,7 @@ func CreateApp(cmd *commands.Command, args []string) int {
os.MkdirAll(appPath, 0755) os.MkdirAll(appPath, 0755)
if module == `true` { if module == `true` {
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "go.mod"), "\x1b[0m") fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "go.mod"), "\x1b[0m")
utils.WriteToFile(path.Join(appPath, "go.mod"), fmt.Sprintf(goMod, packPath, runtime.Version()[2:], beegoVersion.String())) utils.WriteToFile(path.Join(appPath, "go.mod"), fmt.Sprintf(goMod, packPath, utils.GetGoVersionSkipMinor(), beegoVersion.String()))
} }
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", appPath+string(path.Separator), "\x1b[0m") fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", appPath+string(path.Separator), "\x1b[0m")
os.Mkdir(path.Join(appPath, "conf"), 0755) os.Mkdir(path.Join(appPath, "conf"), 0755)

View File

@ -435,7 +435,7 @@ func analyseControllerPkg(vendorPath, localName, pkgpath string) {
pkgRealpath := "" pkgRealpath := ""
if os.Getenv(`GO111MODULE`) == `on` { if bu.IsGOMODULE() {
pkgRealpath = filepath.Join(bu.GetBeeWorkPath(), "..", pkgpath) pkgRealpath = filepath.Join(bu.GetBeeWorkPath(), "..", pkgpath)
} else { } else {
gopaths := bu.GetGOPATHs() gopaths := bu.GetGOPATHs()

View File

@ -447,3 +447,19 @@ func defaultGOPATH() string {
} }
return "" return ""
} }
func GetGoVersionSkipMinor() string {
strArray := strings.Split(runtime.Version()[2:], `.`)
return strArray[0] + `.` + strArray[1]
}
func IsGOMODULE() bool {
if combinedOutput, e := exec.Command(`go`, `env`).CombinedOutput(); e != nil {
beeLogger.Log.Errorf("i cann't find go.")
} else {
regex := regexp.MustCompile(`GOMOD="?(.+go.mod)"?`)
stringSubmatch := regex.FindStringSubmatch(string(combinedOutput))
return len(stringSubmatch) == 2
}
return false
}