Use any in place of interface{} (#7566)

Earlier this evening I tried to run the Go
[modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize)
analyzer on OPA. That didn't go as planned:

- https://github.com/golang/go/issues/73661
- https://github.com/golang/go/issues/73663

While we wait for that to be fixed, I figured an old-fashioned
search-and-replace across the repo may work for at least the
`interface{}` to `any` conversion. That should help make it easier
to see the other fixes as applied by the modernize tool once it has
had those issues resolved.

Signed-off-by: Anders Eknert <anders@styra.com>
This commit is contained in:
Anders Eknert
2025-05-12 13:57:48 +02:00
committed by GitHub
parent f3cb38dc05
commit e43ef0a979
336 changed files with 2872 additions and 2872 deletions
+2 -2
View File
@@ -11,9 +11,9 @@ import (
// Compare returns 0 if a equals b, -1 if a is less than b, and 1 if b is than a.
//
// For comparison between values of different types, the following ordering is used:
// nil < bool < int, float64 < string < []interface{} < map[string]interface{}. Slices and maps
// nil < bool < int, float64 < string < []any < map[string]any. Slices and maps
// are compared recursively. If one slice or map is a subset of the other slice or map
// it is considered "less than". Nil is always equal to nil.
func Compare(a, b interface{}) int {
func Compare(a, b any) int {
return v1.Compare(a, b)
}
+6 -6
View File
@@ -16,7 +16,7 @@ import (
//
// This function is intended to be used in place of the standard json.Marshal
// function when json.Number is required.
func UnmarshalJSON(bs []byte, x interface{}) error {
func UnmarshalJSON(bs []byte, x any) error {
return v1.UnmarshalJSON(bs, x)
}
@@ -32,7 +32,7 @@ func NewJSONDecoder(r io.Reader) *json.Decoder {
//
// If the data cannot be decoded, this function will panic. This function is for
// test purposes.
func MustUnmarshalJSON(bs []byte) interface{} {
func MustUnmarshalJSON(bs []byte) any {
return v1.MustUnmarshalJSON(bs)
}
@@ -40,7 +40,7 @@ func MustUnmarshalJSON(bs []byte) interface{} {
//
// If the data cannot be encoded, this function will panic. This function is for
// test purposes.
func MustMarshalJSON(x interface{}) []byte {
func MustMarshalJSON(x any) []byte {
return v1.MustMarshalJSON(x)
}
@@ -49,7 +49,7 @@ func MustMarshalJSON(x interface{}) []byte {
// Thereby, it is converting its argument to the representation expected by
// rego.Input and inmem's Write operations. Works with both references and
// values.
func RoundTrip(x *interface{}) error {
func RoundTrip(x *any) error {
return v1.RoundTrip(x)
}
@@ -58,11 +58,11 @@ func RoundTrip(x *interface{}) error {
//
// Used for preparing Go types (including pointers to structs) into values to be
// put through util.RoundTrip().
func Reference(x interface{}) *interface{} {
func Reference(x any) *any {
return v1.Reference(x)
}
// Unmarshal decodes a YAML, JSON or JSON extension value into the specified type.
func Unmarshal(bs []byte, v interface{}) error {
func Unmarshal(bs []byte, v any) error {
return v1.Unmarshal(bs, v)
}
+4 -4
View File
@@ -34,25 +34,25 @@ func ObjectIterationBenchmarkModule(n int) string {
// GenerateLargeJSONBenchmarkData returns a map of 100 keys and 100.000 key/value
// pairs.
func GenerateLargeJSONBenchmarkData() map[string]interface{} {
func GenerateLargeJSONBenchmarkData() map[string]any {
return v1.GenerateLargeJSONBenchmarkData()
}
// GenerateJSONBenchmarkData returns a map of `k` keys and `v` key/value pairs.
func GenerateJSONBenchmarkData(k, v int) map[string]interface{} {
func GenerateJSONBenchmarkData(k, v int) map[string]any {
return v1.GenerateJSONBenchmarkData(k, v)
}
// GenerateConcurrencyBenchmarkData returns a module and data; the module
// checks some input parameters against that data in a simple API authz
// scheme.
func GenerateConcurrencyBenchmarkData() (string, map[string]interface{}) {
func GenerateConcurrencyBenchmarkData() (string, map[string]any) {
return v1.GenerateConcurrencyBenchmarkData()
}
// GenerateVirtualDocsBenchmarkData generates a module and input; the
// numTotalRules and numHitRules create as many rules in the module to
// match/miss the returned input.
func GenerateVirtualDocsBenchmarkData(numTotalRules, numHitRules int) (string, map[string]interface{}) {
func GenerateVirtualDocsBenchmarkData(numTotalRules, numHitRules int) (string, map[string]any) {
return v1.GenerateVirtualDocsBenchmarkData(numTotalRules, numHitRules)
}