@@ -4,14 +4,14 @@ package generate
4
4
import (
5
5
"bufio"
6
6
"bytes"
7
- "context"
8
7
"encoding/json"
9
8
"errors"
10
9
"fmt"
11
10
"net/url"
12
11
"os"
13
12
"path/filepath"
14
13
"regexp"
14
+ "sort"
15
15
"strconv"
16
16
"strings"
17
17
"text/template"
@@ -802,29 +802,54 @@ func getSubFiles(selectFiles map[string][]string, replaceFiles map[string][]stri
802
802
return files
803
803
}
804
804
805
+ type Version struct {
806
+ major string
807
+ minor string
808
+ patch string
809
+ goVersion string
810
+ }
811
+
805
812
func getLocalGoVersion () string {
806
813
result , err := gobash .Exec ("go" , "version" )
807
814
if err != nil {
808
815
return defaultGoModVersion
809
816
}
810
817
811
- pattern := `go(\d+\.\d+)`
812
- re := regexp .MustCompile (pattern )
813
- matches := re .FindStringSubmatch (string (result ))
814
- if len (matches ) < 2 {
815
- return defaultGoModVersion
818
+ versions := []string {
819
+ strings .ReplaceAll (defaultGoModVersion , " " , "" ),
820
+ string (result ),
816
821
}
817
822
818
- localGoVersion := "go " + matches [1 ]
819
- if localGoVersion < defaultGoModVersion {
820
- return defaultGoModVersion
823
+ versionRegex := regexp .MustCompile (`go(\d+)\.(\d+)(\.(\d+))?` )
824
+
825
+ var versionList []Version
826
+ for _ , v := range versions {
827
+ matches := versionRegex .FindStringSubmatch (v )
828
+ if len (matches ) >= 3 {
829
+ goVersion := "go " + matches [1 ] + "." + matches [2 ]
830
+ if matches [4 ] != "" {
831
+ goVersion += "." + matches [4 ]
832
+ }
833
+ versionList = append (versionList , Version {major : matches [1 ], minor : matches [2 ], patch : matches [4 ], goVersion : goVersion })
834
+ }
821
835
}
822
836
823
- if len (localGoVersion ) != 6 && len (localGoVersion ) != 7 {
837
+ // descending sort by major, minor, patch
838
+ sort .Slice (versionList , func (i , j int ) bool {
839
+ if versionList [i ].major != versionList [j ].major {
840
+ return utils .StrToInt (versionList [i ].major ) > utils .StrToInt (versionList [j ].major )
841
+ }
842
+ if versionList [i ].minor != versionList [j ].minor {
843
+ return utils .StrToInt (versionList [i ].minor ) > utils .StrToInt (versionList [j ].minor )
844
+ }
845
+ return utils .StrToInt (versionList [i ].patch ) > utils .StrToInt (versionList [j ].patch )
846
+ })
847
+
848
+ if len (versionList ) == 0 {
824
849
return defaultGoModVersion
825
850
}
826
851
827
- return localGoVersion
852
+ return versionList [ 0 ]. goVersion
828
853
}
829
854
830
855
func dbDriverErr (driver string ) error {
@@ -1055,30 +1080,3 @@ func getGRPCServiceFields() []replacer.Field {
1055
1080
},
1056
1081
}
1057
1082
}
1058
-
1059
- func clearCurrentLine () {
1060
- fmt .Print ("\033 [2K\r " )
1061
- }
1062
-
1063
- func PrintWaiting (ctx context.Context , runningTip string , finishTip string ) {
1064
- defer func () {
1065
- clearCurrentLine ()
1066
- fmt .Println (finishTip )
1067
- }()
1068
- symbols := []string {runningTip + "." , runningTip + ".." , runningTip + "..." , runningTip + "...." , runningTip + "....." , runningTip + "......" }
1069
- index := 0
1070
- fmt .Printf ("\r %s" , symbols [index ])
1071
- for {
1072
- select {
1073
- case <- ctx .Done ():
1074
- return
1075
- case <- time .After (500 * time .Millisecond ):
1076
- index ++
1077
- if index >= len (symbols ) {
1078
- index = 0
1079
- clearCurrentLine ()
1080
- }
1081
- fmt .Printf ("\r %s" , symbols [index ])
1082
- }
1083
- }
1084
- }
0 commit comments