From 8893ad2d13a61471dfaba7369930a026ec6672a3 Mon Sep 17 00:00:00 2001 From: qiantao Date: Sat, 11 Jul 2020 12:29:24 +0800 Subject: [PATCH] generate go.mod skip Minor version. --- cmd/commands/api/apiapp.go | 3 +-- cmd/commands/hprose/hprose.go | 6 ++---- cmd/commands/new/new.go | 3 +-- utils/utils.go | 5 +++++ 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cmd/commands/api/apiapp.go b/cmd/commands/api/apiapp.go index 1265329..ba0b45f 100644 --- a/cmd/commands/api/apiapp.go +++ b/cmd/commands/api/apiapp.go @@ -19,7 +19,6 @@ import ( "github.com/beego/bee/logger/colors" "os" path "path/filepath" - "runtime" "strings" "github.com/beego/bee/cmd/commands" @@ -608,7 +607,7 @@ func createAPI(cmd *commands.Command, args []string) int { os.MkdirAll(appPath, 0755) 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") - 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") os.Mkdir(path.Join(appPath, "conf"), 0755) diff --git a/cmd/commands/hprose/hprose.go b/cmd/commands/hprose/hprose.go index f926c53..50ba5c1 100644 --- a/cmd/commands/hprose/hprose.go +++ b/cmd/commands/hprose/hprose.go @@ -1,11 +1,9 @@ package hprose import ( + "fmt" "github.com/beego/bee/logger/colors" "os" - "runtime" - - "fmt" "path" "strings" @@ -113,7 +111,7 @@ func createhprose(cmd *commands.Command, args []string) int { os.MkdirAll(apppath, 0755) 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") - 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") os.Mkdir(path.Join(apppath, "conf"), 0755) diff --git a/cmd/commands/new/new.go b/cmd/commands/new/new.go index 98c1aed..9510143 100644 --- a/cmd/commands/new/new.go +++ b/cmd/commands/new/new.go @@ -18,7 +18,6 @@ import ( "fmt" "os" path "path/filepath" - "runtime" "strings" "github.com/beego/bee/cmd/commands" @@ -305,7 +304,7 @@ func CreateApp(cmd *commands.Command, args []string) int { os.MkdirAll(appPath, 0755) 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") - 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") os.Mkdir(path.Join(appPath, "conf"), 0755) diff --git a/utils/utils.go b/utils/utils.go index ce62421..f53d7de 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -447,3 +447,8 @@ func defaultGOPATH() string { } return "" } + +func GetGoVersionSkipMinor() string { + strArray := strings.Split(runtime.Version()[2:], `.`) + return strArray[0] + `.` + strArray[1] +}