Debian Codegraph @

internal/versions/features.go

raw symbols SCIP
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 Go1_27 = "go1.27"
23 )
24
25 // Future is an invalid unknown Go version sometime in the future.
26 // Do not use directly with Compare.
27 const Future = ""
28
29 // AtLeast reports whether the file version v comes after a Go release.
30 //
31 // Use this predicate to enable a behavior once a certain Go release
32 // has happened (and stays enabled in the future).
33 func AtLeast(v, release string) bool {
34 if v == Future {
35 return true // an unknown future version is always after y.
36 }
37 return Compare(Lang(v), Lang(release)) >= 0
38 }
39
40 // Before reports whether the file version v is strictly before a Go release.
41 //
42 // Use this predicate to disable a behavior once a certain Go release
43 // has happened (and stays enabled in the future).
44 func Before(v, release string) bool {
45 if v == Future {
46 return false // an unknown future version happens after y.
47 }
48 return Compare(Lang(v), Lang(release)) < 0
49 }