@@ -34,8 +34,8 @@ import (
34
34
// initialization only imports.
35
35
//
36
36
// Usage:
37
- // node, matched := MatchCallByPackage(n, ctx, "math/rand", "Read")
38
37
//
38
+ // node, matched := MatchCallByPackage(n, ctx, "math/rand", "Read")
39
39
func MatchCallByPackage (n ast.Node , c * Context , pkg string , names ... string ) (* ast.CallExpr , bool ) {
40
40
importedName , found := GetImportedName (pkg , c )
41
41
if ! found {
@@ -474,9 +474,25 @@ func RootPath(root string) (string, error) {
474
474
475
475
// GoVersion returns parsed version of Go from runtime
476
476
func GoVersion () (int , int , int ) {
477
- versionParts := strings .Split (runtime .Version (), "." )
478
- major , _ := strconv .Atoi (versionParts [0 ][2 :])
479
- minor , _ := strconv .Atoi (versionParts [1 ])
480
- build , _ := strconv .Atoi (versionParts [2 ])
477
+ return parseGoVersion (runtime .Version ())
478
+ }
479
+
480
+ // parseGoVersion parses Go version.
481
+ // example:
482
+ // - go1.19rc2
483
+ // - go1.19beta2
484
+ // - go1.19.4
485
+ // - go1.19
486
+ func parseGoVersion (version string ) (int , int , int ) {
487
+ exp := regexp .MustCompile (`go(\d+).(\d+)(?:.(\d+))?.*` )
488
+ parts := exp .FindStringSubmatch (version )
489
+ if len (parts ) <= 1 {
490
+ return 0 , 0 , 0
491
+ }
492
+
493
+ major , _ := strconv .Atoi (parts [1 ])
494
+ minor , _ := strconv .Atoi (parts [2 ])
495
+ build , _ := strconv .Atoi (parts [3 ])
496
+
481
497
return major , minor , build
482
498
}
0 commit comments