1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4 5 package versions
6 7 // This file contains predicates for working with file versions to
8 // decide when a tool should consider a language feature enabled.
9 10 // named constants, to avoid misspelling
11 const (
12 Go1_17 = "go1.17"
13 Go1_18 = "go1.18"
14 Go1_19 = "go1.19"
15 Go1_20 = "go1.20"
16 Go1_21 = "go1.21"
17 Go1_22 = "go1.22"
18 Go1_23 = "go1.23"
19 Go1_24 = "go1.24"
20 Go1_25 = "go1.25"
21 Go1_26 = "go1.26"
22 )
23 24 // Future is an invalid unknown Go version sometime in the future.
25 // Do not use directly with Compare.
26 const Future = ""
27 28 // AtLeast reports whether the file version v comes after a Go release.
29 //
30 // Use this predicate to enable a behavior once a certain Go release
31 // has happened (and stays enabled in the future).
32 func AtLeast(v, release string) bool {
33 if v == Future {
34 return true // an unknown future version is always after y.
35 }
36 return Compare(Lang(v), Lang(release)) >= 0
37 }
38 39 // Before reports whether the file version v is strictly before a Go release.
40 //
41 // Use this predicate to disable a behavior once a certain Go release
42 // has happened (and stays enabled in the future).
43 func Before(v, release string) bool {
44 if v == Future {
45 return false // an unknown future version happens after y.
46 }
47 return Compare(Lang(v), Lang(release)) < 0
48 }
49