features.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. package versions
  5. // This file contains predicates for working with file versions to
  6. // decide when a tool should consider a language feature enabled.
  7. // GoVersions that features in x/tools can be gated to.
  8. const (
  9. Go1_18 = "go1.18"
  10. Go1_19 = "go1.19"
  11. Go1_20 = "go1.20"
  12. Go1_21 = "go1.21"
  13. Go1_22 = "go1.22"
  14. )
  15. // Future is an invalid unknown Go version sometime in the future.
  16. // Do not use directly with Compare.
  17. const Future = ""
  18. // AtLeast reports whether the file version v comes after a Go release.
  19. //
  20. // Use this predicate to enable a behavior once a certain Go release
  21. // has happened (and stays enabled in the future).
  22. func AtLeast(v, release string) bool {
  23. if v == Future {
  24. return true // an unknown future version is always after y.
  25. }
  26. return Compare(Lang(v), Lang(release)) >= 0
  27. }
  28. // Before reports whether the file version v is strictly before a Go release.
  29. //
  30. // Use this predicate to disable a behavior once a certain Go release
  31. // has happened (and stays enabled in the future).
  32. func Before(v, release string) bool {
  33. if v == Future {
  34. return false // an unknown future version happens after y.
  35. }
  36. return Compare(Lang(v), Lang(release)) < 0
  37. }