File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
+ "bufio"
4
5
"fmt"
5
6
"io/ioutil"
6
7
"log"
@@ -56,11 +57,23 @@ func getEnvGoVersion() string {
56
57
if err != nil {
57
58
log .Fatalf ("Unable to run the go command, is it installed?\n Error: %s" , err .Error ())
58
59
}
59
- goVersion = strings . Fields (string (gover ))[ 2 ]
60
+ goVersion = parseGoVersion (string (gover ))
60
61
}
61
62
return goVersion
62
63
}
63
64
65
+ // The 'go version' command may output warnings on separate lines before
66
+ // the actual version string is printed. This function parses the output
67
+ // to retrieve just the version string.
68
+ func parseGoVersion (data string ) string {
69
+ var lastLine string
70
+ sc := bufio .NewScanner (strings .NewReader (data ))
71
+ for sc .Scan () {
72
+ lastLine = sc .Text ()
73
+ }
74
+ return strings .Fields (lastLine )[2 ]
75
+ }
76
+
64
77
// Returns the current Go version in semver format, e.g. v1.14.4
65
78
func getEnvGoSemVer () string {
66
79
goVersion := getEnvGoVersion ()
You can’t perform that action at this time.
0 commit comments