Skip to content

Commit f431df9

Browse files
authored
chore: migrate from interface{} to any (#3162)
* chore: migrate from interface{} to any * Fix * Fix
1 parent ba000af commit f431df9

File tree

298 files changed

+1550
-1545
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

298 files changed

+1550
-1545
lines changed

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ formatters:
55
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
66
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
77
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
8+
settings:
9+
gofmt:
10+
rewrite-rules:
11+
- pattern: interface{}
12+
replacement: any
813

914
linters:
1015
# Run golangci-lint linters to see the list of all linters

cmd/vcr-compressor/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func main() {
6868
continue
6969
}
7070

71-
var m map[string]interface{}
71+
var m map[string]any
7272

7373
err := json.Unmarshal([]byte(responseBody), &m)
7474
if err != nil {

cmd/vcr-viewer/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func main() {
3737
log.Printf(" Status: %s\n", interaction.Response.Status)
3838
log.Printf(" Body: %s\n", interaction.Response.Body)
3939

40-
var m map[string]interface{}
40+
var m map[string]any
4141

4242
err := json.Unmarshal([]byte(interaction.Response.Body), &m)
4343
if err != nil {

internal/acctest/acctest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func compareJSONFieldsStrings(expected, actual string) bool {
131131

132132
// compareJSONBodies compare two given maps that represent json bodies
133133
// returns true if both json are equivalent
134-
func compareJSONBodies(expected, actual map[string]interface{}) bool {
134+
func compareJSONBodies(expected, actual map[string]any) bool {
135135
// Check for each key in actual requests
136136
// Compare its value to cassette content if marshal-able to string
137137
for key := range actual {

internal/acctest/vcr.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var UpdateCassettes = flag.Bool("cassettes", os.Getenv("TF_UPDATE_CASSETTES") ==
2828

2929
// SensitiveFields is a map with keys listing fields that should be anonymized
3030
// value will be set in place of its old value
31-
var SensitiveFields = map[string]interface{}{
31+
var SensitiveFields = map[string]any{
3232
"secret_key": "00000000-0000-0000-0000-000000000000",
3333
}
3434

@@ -65,7 +65,7 @@ func getTestFilePath(t *testing.T, pkgFolder string, suffix string) string {
6565
return filepath.Join(pkgFolder, "testdata", fileName)
6666
}
6767

68-
func compareJSONFields(expected, actualI interface{}) bool {
68+
func compareJSONFields(expected, actualI any) bool {
6969
switch actual := actualI.(type) {
7070
case string:
7171
if _, isString := expected.(string); !isString {
@@ -138,10 +138,10 @@ func cassetteBodyMatcher(actualRequest *http.Request, cassetteRequest cassette.R
138138
return true
139139
}
140140

141-
actualJSON := make(map[string]interface{})
142-
cassetteJSON := make(map[string]interface{})
141+
actualJSON := make(map[string]any)
142+
cassetteJSON := make(map[string]any)
143143

144-
err = xml.Unmarshal(actualRawBody, new(interface{}))
144+
err = xml.Unmarshal(actualRawBody, new(any))
145145
if err == nil {
146146
// match if content is xml
147147
return true
@@ -236,7 +236,7 @@ func cassetteMatcher(actual *http.Request, expected cassette.Request) bool {
236236
}
237237

238238
func cassetteSensitiveFieldsAnonymizer(i *cassette.Interaction) error {
239-
var jsonBody map[string]interface{}
239+
var jsonBody map[string]any
240240

241241
err := json.Unmarshal([]byte(i.Response.Body), &jsonBody)
242242
if err != nil {

internal/cdf/locality.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func expandListKeys(key string, diff *schema.ResourceDiff) []string {
4545
// getLocality find the locality of a resource
4646
// Will try to get the zone if available then use region
4747
// Will also use default zone or region if available
48-
func getLocality(diff *schema.ResourceDiff, m interface{}) string {
48+
func getLocality(diff *schema.ResourceDiff, m any) string {
4949
var loc string
5050

5151
rawStateType := diff.GetRawState().Type()
@@ -67,7 +67,7 @@ func getLocality(diff *schema.ResourceDiff, m interface{}) string {
6767
// Should not be used on computed keys, if a computed key is going to change on zone/region change
6868
// this function will still block the terraform plan
6969
func LocalityCheck(keys ...string) schema.CustomizeDiffFunc {
70-
return func(_ context.Context, diff *schema.ResourceDiff, m interface{}) error {
70+
return func(_ context.Context, diff *schema.ResourceDiff, m any) error {
7171
l := getLocality(diff, m)
7272

7373
if l == "" {

internal/datasource/schemas.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
88
)
99

10-
func NewZonedID(idI interface{}, fallBackZone scw.Zone) string {
10+
func NewZonedID(idI any, fallBackZone scw.Zone) string {
1111
zone, id, err := zonal.ParseID(idI.(string))
1212
if err != nil {
1313
id = idI.(string)
@@ -17,7 +17,7 @@ func NewZonedID(idI interface{}, fallBackZone scw.Zone) string {
1717
return zonal.NewIDString(zone, id)
1818
}
1919

20-
func NewRegionalID(idI interface{}, fallBackRegion scw.Region) string {
20+
func NewRegionalID(idI any, fallBackRegion scw.Region) string {
2121
region, id, err := regional.ParseID(idI.(string))
2222
if err != nil {
2323
id = idI.(string)

internal/datasource/search.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func notFound(err error) bool {
6060
}
6161

6262
type TooManyResultsError struct {
63-
LastRequest interface{}
63+
LastRequest any
6464
Count int
6565
}
6666

@@ -74,7 +74,7 @@ func (e *TooManyResultsError) Is(err error) bool {
7474
return ok
7575
}
7676

77-
func (e *TooManyResultsError) As(target interface{}) bool {
77+
func (e *TooManyResultsError) As(target any) bool {
7878
t, ok := target.(**retry.NotFoundError)
7979
if !ok {
8080
return false

internal/dsf/list.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ func ExtractBaseKey(k string) string {
2929
func GetStringListsFromState(key string, d *schema.ResourceData) ([]string, []string) {
3030
oldList, newList := d.GetChange(key)
3131

32-
oldListStr := make([]string, len(oldList.([]interface{})))
33-
newListStr := make([]string, len(newList.([]interface{})))
32+
oldListStr := make([]string, len(oldList.([]any)))
33+
newListStr := make([]string, len(newList.([]any)))
3434

35-
for i, v := range oldList.([]interface{}) {
35+
for i, v := range oldList.([]any) {
3636
oldListStr[i] = fmt.Sprint(v)
3737
}
3838

39-
for i, v := range newList.([]interface{}) {
39+
for i, v := range newList.([]any) {
4040
newListStr[i] = fmt.Sprint(v)
4141
}
4242

internal/locality/ids.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package locality
22

33
// ExpandID returns the id whether it is a localizedID or a raw ID.
4-
func ExpandID(id interface{}) string {
4+
func ExpandID(id any) string {
55
_, ID, err := ParseLocalizedID(id.(string))
66
if err != nil {
77
return id.(string)
@@ -10,10 +10,10 @@ func ExpandID(id interface{}) string {
1010
return ID
1111
}
1212

13-
func ExpandIDs(data interface{}) []string {
14-
expandedIDs := make([]string, 0, len(data.([]interface{})))
13+
func ExpandIDs(data any) []string {
14+
expandedIDs := make([]string, 0, len(data.([]any)))
1515

16-
for _, s := range data.([]interface{}) {
16+
for _, s := range data.([]any) {
1717
if s == nil {
1818
s = ""
1919
}

0 commit comments

Comments
 (0)