From d04f11c57a40d4cb479e637ff00326a3fac7d82a Mon Sep 17 00:00:00 2001 From: Ming Deng Date: Mon, 29 Mar 2021 23:11:14 +0800 Subject: [PATCH 1/3] Fix 767 --- cmd/commands/version/version.go | 72 +++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/cmd/commands/version/version.go b/cmd/commands/version/version.go index 6470d84..b57511e 100644 --- a/cmd/commands/version/version.go +++ b/cmd/commands/version/version.go @@ -1,16 +1,17 @@ package version import ( + "bufio" "bytes" "encoding/json" "flag" "fmt" - "os" - "os/exec" - "runtime" - "strings" - "gopkg.in/yaml.v2" + "io" + "os" + path "path/filepath" + "regexp" + "runtime" "github.com/beego/bee/v2/cmd/commands" "github.com/beego/bee/v2/config" @@ -26,6 +27,7 @@ const verboseVersionBanner string = `%s%s______ | |_/ /| __/| __/ \____/ \___| \___| v{{ .BeeVersion }}%s %s%s +├── Beego : {{ .BeegoVersion }} ├── GoVersion : {{ .GoVersion }} ├── GOOS : {{ .GOOS }} ├── GOARCH : {{ .GOARCH }} @@ -33,7 +35,7 @@ const verboseVersionBanner string = `%s%s______ ├── GOPATH : {{ .GOPATH }} ├── GOROOT : {{ .GOROOT }} ├── Compiler : {{ .Compiler }} -└── Published : {{ .Published }}%s +└── Date : {{ Now "Monday, 2 Jan 2006" }}%s ` const shortVersionBanner = `______ @@ -78,7 +80,7 @@ func versionCmd(cmd *commands.Command, args []string) int { runtime.GOROOT(), runtime.Compiler, version, - utils.GetLastPublishedTime(), + GetBeegoVersion(), } switch outputFormat { case "json": @@ -114,14 +116,52 @@ func ShowShortVersionBanner() { InitBanner(output, bytes.NewBufferString(colors.MagentaBold(shortVersionBanner))) } -func GetGoVersion() string { - var ( - cmdOut []byte - err error - ) - - if cmdOut, err = exec.Command("go", "version").Output(); err != nil { - beeLogger.Log.Fatalf("There was an error running 'go version' command: %s", err) +func GetBeegoVersion() string { + re, err := regexp.Compile(`VERSION = "([0-9.]+)"`) + if err != nil { + return "" } - return strings.Split(string(cmdOut), " ")[2] + wgopath := utils.GetGOPATHs() + if len(wgopath) == 0 { + beeLogger.Log.Error("GOPATH environment is empty,may be you use `go module`") + return "" + } + for _, wg := range wgopath { + wg, _ = path.EvalSymlinks(path.Join(wg, "src", "github.com", "astaxie", "beego")) + filename := path.Join(wg, "beego.go") + _, err := os.Stat(filename) + if err != nil { + if os.IsNotExist(err) { + continue + } + beeLogger.Log.Error("Error while getting stats of 'beego.go'") + } + fd, err := os.Open(filename) + if err != nil { + beeLogger.Log.Error("Error while reading 'beego.go'") + continue + } + reader := bufio.NewReader(fd) + for { + byteLine, _, er := reader.ReadLine() + if er != nil && er != io.EOF { + return "" + } + if er == io.EOF { + break + } + line := string(byteLine) + s := re.FindStringSubmatch(line) + if len(s) >= 2 { + return s[1] + } + } + + } + return "Beego is not installed. Please do consider installing it first: https://github.com/beego/beego/v2. " + + "If you are using go mod, and you don't install the beego under $GOPATH/src/github.com/astaxie, just ignore this." +} + +func GetGoVersion() string { + return runtime.Version() } From 97df75a28cdf639e9edb7a6f0125843c935f3a61 Mon Sep 17 00:00:00 2001 From: zhangqz Date: Fri, 30 Apr 2021 14:14:47 +0800 Subject: [PATCH 2/3] fix required struct tag when anonymous nested struct --- generate/swaggergen/g_docs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index bc33133..23f16ac 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -1252,6 +1252,7 @@ func parseStruct(imports []*ast.ImportSpec, st *ast.StructType, k string, m *swa for name, p := range nm.Properties { m.Properties[name] = p } + m.Required = append(m.Required, nm.Required...) continue } } From afe16784592ea3599b6c6659836298ea7b3e536a Mon Sep 17 00:00:00 2001 From: Deng Ming Date: Fri, 10 Jun 2022 18:54:40 +0800 Subject: [PATCH 3/3] fix Beego#4972: bee version failed --- cmd/commands/version/banner.go | 20 ++++----- cmd/commands/version/version.go | 73 ++++----------------------------- config/conf.go | 2 +- 3 files changed, 19 insertions(+), 76 deletions(-) diff --git a/cmd/commands/version/banner.go b/cmd/commands/version/banner.go index 69954e8..b41ebf7 100644 --- a/cmd/commands/version/banner.go +++ b/cmd/commands/version/banner.go @@ -15,15 +15,15 @@ import ( // RuntimeInfo holds information about the current runtime. type RuntimeInfo struct { - GoVersion string - GOOS string - GOARCH string - NumCPU int - GOPATH string - GOROOT string - Compiler string - BeeVersion string - Published string + GoVersion string + GOOS string + GOARCH string + NumCPU int + GOPATH string + GOROOT string + Compiler string + BeeVersion string + Published string } // InitBanner loads the banner and prints it to output @@ -52,7 +52,7 @@ func show(out io.Writer, content string) { } err = t.Execute(out, RuntimeInfo{ - GetGoVersion(), + runtime.Version(), runtime.GOOS, runtime.GOARCH, runtime.NumCPU(), diff --git a/cmd/commands/version/version.go b/cmd/commands/version/version.go index b57511e..fd8d68a 100644 --- a/cmd/commands/version/version.go +++ b/cmd/commands/version/version.go @@ -1,23 +1,18 @@ package version import ( - "bufio" "bytes" "encoding/json" "flag" "fmt" "gopkg.in/yaml.v2" - "io" "os" - path "path/filepath" - "regexp" "runtime" "github.com/beego/bee/v2/cmd/commands" "github.com/beego/bee/v2/config" beeLogger "github.com/beego/bee/v2/logger" "github.com/beego/bee/v2/logger/colors" - "github.com/beego/bee/v2/utils" ) const verboseVersionBanner string = `%s%s______ @@ -27,7 +22,6 @@ const verboseVersionBanner string = `%s%s______ | |_/ /| __/| __/ \____/ \___| \___| v{{ .BeeVersion }}%s %s%s -├── Beego : {{ .BeegoVersion }} ├── GoVersion : {{ .GoVersion }} ├── GOOS : {{ .GOOS }} ├── GOARCH : {{ .GOARCH }} @@ -72,15 +66,14 @@ func versionCmd(cmd *commands.Command, args []string) int { if outputFormat != "" { runtimeInfo := RuntimeInfo{ - GetGoVersion(), - runtime.GOOS, - runtime.GOARCH, - runtime.NumCPU(), - os.Getenv("GOPATH"), - runtime.GOROOT(), - runtime.Compiler, - version, - GetBeegoVersion(), + GoVersion: runtime.Version(), + GOOS: runtime.GOOS, + GOARCH: runtime.GOARCH, + NumCPU: runtime.NumCPU(), + GOPATH: os.Getenv("GOPATH"), + GOROOT: runtime.GOROOT(), + Compiler: runtime.Compiler, + BeeVersion: version, } switch outputFormat { case "json": @@ -115,53 +108,3 @@ func ShowShortVersionBanner() { output := colors.NewColorWriter(os.Stdout) InitBanner(output, bytes.NewBufferString(colors.MagentaBold(shortVersionBanner))) } - -func GetBeegoVersion() string { - re, err := regexp.Compile(`VERSION = "([0-9.]+)"`) - if err != nil { - return "" - } - wgopath := utils.GetGOPATHs() - if len(wgopath) == 0 { - beeLogger.Log.Error("GOPATH environment is empty,may be you use `go module`") - return "" - } - for _, wg := range wgopath { - wg, _ = path.EvalSymlinks(path.Join(wg, "src", "github.com", "astaxie", "beego")) - filename := path.Join(wg, "beego.go") - _, err := os.Stat(filename) - if err != nil { - if os.IsNotExist(err) { - continue - } - beeLogger.Log.Error("Error while getting stats of 'beego.go'") - } - fd, err := os.Open(filename) - if err != nil { - beeLogger.Log.Error("Error while reading 'beego.go'") - continue - } - reader := bufio.NewReader(fd) - for { - byteLine, _, er := reader.ReadLine() - if er != nil && er != io.EOF { - return "" - } - if er == io.EOF { - break - } - line := string(byteLine) - s := re.FindStringSubmatch(line) - if len(s) >= 2 { - return s[1] - } - } - - } - return "Beego is not installed. Please do consider installing it first: https://github.com/beego/beego/v2. " + - "If you are using go mod, and you don't install the beego under $GOPATH/src/github.com/astaxie, just ignore this." -} - -func GetGoVersion() string { - return runtime.Version() -} diff --git a/config/conf.go b/config/conf.go index d570213..073d92f 100644 --- a/config/conf.go +++ b/config/conf.go @@ -27,7 +27,7 @@ import ( const confVer = 0 const ( - Version = "2.0.2" + Version = "2.0.3" GitRemotePath = "github.com/beego/bee/v2" )