Source file src/cmd/vendor/golang.org/x/tools/internal/versions/features.go
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_18 = "go1.18" 13 Go1_19 = "go1.19" 14 Go1_20 = "go1.20" 15 Go1_21 = "go1.21" 16 Go1_22 = "go1.22" 17 Go1_23 = "go1.23" 18 Go1_24 = "go1.24" 19 Go1_25 = "go1.25" 20 Go1_26 = "go1.26" 21 ) 22 23 // Future is an invalid unknown Go version sometime in the future. 24 // Do not use directly with Compare. 25 const Future = "" 26 27 // AtLeast reports whether the file version v comes after a Go release. 28 // 29 // Use this predicate to enable a behavior once a certain Go release 30 // has happened (and stays enabled in the future). 31 func AtLeast(v, release string) bool { 32 if v == Future { 33 return true // an unknown future version is always after y. 34 } 35 return Compare(Lang(v), Lang(release)) >= 0 36 } 37 38 // Before reports whether the file version v is strictly before a Go release. 39 // 40 // Use this predicate to disable a behavior once a certain Go release 41 // has happened (and stays enabled in the future). 42 func Before(v, release string) bool { 43 if v == Future { 44 return false // an unknown future version happens after y. 45 } 46 return Compare(Lang(v), Lang(release)) < 0 47 } 48