1
1
package version
2
2
3
3
import (
4
- "bufio"
5
4
"bytes"
6
5
"encoding/json"
7
6
"flag"
8
7
"fmt"
9
8
"gopkg.in/yaml.v2"
10
- "io"
11
9
"os"
12
- path "path/filepath"
13
- "regexp"
14
10
"runtime"
15
11
16
12
"github.com/beego/bee/v2/cmd/commands"
17
13
"github.com/beego/bee/v2/config"
18
14
beeLogger "github.com/beego/bee/v2/logger"
19
15
"github.com/beego/bee/v2/logger/colors"
20
- "github.com/beego/bee/v2/utils"
21
16
)
22
17
23
18
const verboseVersionBanner string = `%s%s______
@@ -27,7 +22,6 @@ const verboseVersionBanner string = `%s%s______
27
22
| |_/ /| __/| __/
28
23
\____/ \___| \___| v{{ .BeeVersion }}%s
29
24
%s%s
30
- ├── Beego : {{ .BeegoVersion }}
31
25
├── GoVersion : {{ .GoVersion }}
32
26
├── GOOS : {{ .GOOS }}
33
27
├── GOARCH : {{ .GOARCH }}
@@ -72,15 +66,14 @@ func versionCmd(cmd *commands.Command, args []string) int {
72
66
73
67
if outputFormat != "" {
74
68
runtimeInfo := RuntimeInfo {
75
- GetGoVersion (),
76
- runtime .GOOS ,
77
- runtime .GOARCH ,
78
- runtime .NumCPU (),
79
- os .Getenv ("GOPATH" ),
80
- runtime .GOROOT (),
81
- runtime .Compiler ,
82
- version ,
83
- GetBeegoVersion (),
69
+ GoVersion : runtime .Version (),
70
+ GOOS : runtime .GOOS ,
71
+ GOARCH : runtime .GOARCH ,
72
+ NumCPU : runtime .NumCPU (),
73
+ GOPATH : os .Getenv ("GOPATH" ),
74
+ GOROOT : runtime .GOROOT (),
75
+ Compiler : runtime .Compiler ,
76
+ BeeVersion : version ,
84
77
}
85
78
switch outputFormat {
86
79
case "json" :
@@ -115,53 +108,3 @@ func ShowShortVersionBanner() {
115
108
output := colors .NewColorWriter (os .Stdout )
116
109
InitBanner (output , bytes .NewBufferString (colors .MagentaBold (shortVersionBanner )))
117
110
}
118
-
119
- func GetBeegoVersion () string {
120
- re , err := regexp .Compile (`VERSION = "([0-9.]+)"` )
121
- if err != nil {
122
- return ""
123
- }
124
- wgopath := utils .GetGOPATHs ()
125
- if len (wgopath ) == 0 {
126
- beeLogger .Log .Error ("GOPATH environment is empty,may be you use `go module`" )
127
- return ""
128
- }
129
- for _ , wg := range wgopath {
130
- wg , _ = path .EvalSymlinks (path .Join (wg , "src" , "github.com" , "astaxie" , "beego" ))
131
- filename := path .Join (wg , "beego.go" )
132
- _ , err := os .Stat (filename )
133
- if err != nil {
134
- if os .IsNotExist (err ) {
135
- continue
136
- }
137
- beeLogger .Log .Error ("Error while getting stats of 'beego.go'" )
138
- }
139
- fd , err := os .Open (filename )
140
- if err != nil {
141
- beeLogger .Log .Error ("Error while reading 'beego.go'" )
142
- continue
143
- }
144
- reader := bufio .NewReader (fd )
145
- for {
146
- byteLine , _ , er := reader .ReadLine ()
147
- if er != nil && er != io .EOF {
148
- return ""
149
- }
150
- if er == io .EOF {
151
- break
152
- }
153
- line := string (byteLine )
154
- s := re .FindStringSubmatch (line )
155
- if len (s ) >= 2 {
156
- return s [1 ]
157
- }
158
- }
159
-
160
- }
161
- return "Beego is not installed. Please do consider installing it first: https://github.com/beego/beego/v2. " +
162
- "If you are using go mod, and you don't install the beego under $GOPATH/src/github.com/astaxie, just ignore this."
163
- }
164
-
165
- func GetGoVersion () string {
166
- return runtime .Version ()
167
- }
0 commit comments