1
2
3
4
5 package types2
6
7 import (
8 "fmt"
9 "go/version"
10 "internal/goversion"
11 )
12
13
14
15
16 type goVersion string
17
18
19
20 func asGoVersion(v string) goVersion {
21 return goVersion(version.Lang(v))
22 }
23
24
25 func (v goVersion) isValid() bool {
26 return v != ""
27 }
28
29
30
31 func (x goVersion) cmp(y goVersion) int {
32 return version.Compare(string(x), string(y))
33 }
34
35 var (
36
37 go1_9 = asGoVersion("go1.9")
38 go1_13 = asGoVersion("go1.13")
39 go1_14 = asGoVersion("go1.14")
40 go1_17 = asGoVersion("go1.17")
41 go1_18 = asGoVersion("go1.18")
42 go1_20 = asGoVersion("go1.20")
43 go1_21 = asGoVersion("go1.21")
44 go1_22 = asGoVersion("go1.22")
45 go1_23 = asGoVersion("go1.23")
46
47
48 go_current = asGoVersion(fmt.Sprintf("go1.%d", goversion.Version))
49 )
50
51
52
53
54 func (check *Checker) allowVersion(want goVersion) bool {
55 return !check.version.isValid() || check.version.cmp(want) >= 0
56 }
57
58
59
60 func (check *Checker) verifyVersionf(at poser, v goVersion, format string, args ...interface{}) bool {
61 if !check.allowVersion(v) {
62 check.versionErrorf(at, v, format, args...)
63 return false
64 }
65 return true
66 }
67
View as plain text