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
}

internal/locality/regional/ids.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (z ID) String() string {
2525
return fmt.Sprintf("%s/%s", z.Region, z.ID)
2626
}
2727

28-
func ExpandID(id interface{}) ID {
28+
func ExpandID(id any) ID {
2929
regionalID := ID{}
3030
tab := strings.Split(id.(string), "/")
3131

internal/locality/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
// ValidateStringInSliceWithWarning helps to only returns warnings in case we got a non-public locality passed
1111
func ValidateStringInSliceWithWarning(correctValues []string, field string) schema.SchemaValidateDiagFunc {
12-
return func(i interface{}, path cty.Path) diag.Diagnostics {
12+
return func(i any, path cty.Path) diag.Diagnostics {
1313
_, rawErr := validation.StringInSlice(correctValues, true)(i, field)
1414

1515
var res diag.Diagnostics

internal/locality/zonal/ids.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (z ID) String() string {
2525
return fmt.Sprintf("%s/%s", z.Zone, z.ID)
2626
}
2727

28-
func ExpandID(id interface{}) ID {
28+
func ExpandID(id any) ID {
2929
zonedID := ID{}
3030
tab := strings.Split(id.(string), "/")
3131

internal/logging/logger.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ type Logger struct{}
2020
var L = Logger{}
2121

2222
// Debugf logs to the DEBUG log. Arguments are handled in the manner of fmt.Printf.
23-
func (l Logger) Debugf(format string, args ...interface{}) {
23+
func (l Logger) Debugf(format string, args ...any) {
2424
log.Printf("[DEBUG] "+format, args...)
2525
}
2626

2727
// Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf.
28-
func (l Logger) Infof(format string, args ...interface{}) {
28+
func (l Logger) Infof(format string, args ...any) {
2929
log.Printf("[INFO] "+format, args...)
3030
}
3131

3232
// Warningf logs to the WARNING log. Arguments are handled in the manner of fmt.Printf.
33-
func (l Logger) Warningf(format string, args ...interface{}) {
33+
func (l Logger) Warningf(format string, args ...any) {
3434
log.Printf("[WARN] "+format, args...)
3535
}
3636

3737
// Errorf logs to the ERROR log. Arguments are handled in the manner of fmt.Printf.
38-
func (l Logger) Errorf(format string, args ...interface{}) {
38+
func (l Logger) Errorf(format string, args ...any) {
3939
log.Printf("[ERROR] "+format, args...)
4040
}
4141

4242
// Printf logs to the DEBUG log. Arguments are handled in the manner of fmt.Printf.
43-
func (l Logger) Printf(format string, args ...interface{}) {
43+
func (l Logger) Printf(format string, args ...any) {
4444
l.Debugf(format, args...)
4545
}
4646

internal/meta/extractors.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import (
1515
// terraformResourceData is an interface for *schema.ResourceData. (used for mock)
1616
type terraformResourceData interface {
1717
HasChange(string) bool
18-
GetOk(string) (interface{}, bool)
19-
Get(string) interface{}
18+
GetOk(string) (any, bool)
19+
Get(string) any
2020
Id() string
2121
}
2222

2323
// ExtractZone will try to guess the zone from the following:
2424
// - zone field of the resource data
2525
// - default zone from config
26-
func ExtractZone(d terraformResourceData, m interface{}) (scw.Zone, error) {
26+
func ExtractZone(d terraformResourceData, m any) (scw.Zone, error) {
2727
rawZone, exist := d.GetOk("zone")
2828
if exist {
2929
return scw.ParseZone(rawZone.(string))
@@ -40,7 +40,7 @@ func ExtractZone(d terraformResourceData, m interface{}) (scw.Zone, error) {
4040
// ExtractRegion will try to guess the region from the following:
4141
// - region field of the resource data
4242
// - default region from config
43-
func ExtractRegion(d terraformResourceData, m interface{}) (scw.Region, error) {
43+
func ExtractRegion(d terraformResourceData, m any) (scw.Region, error) {
4444
rawRegion, exist := d.GetOk("region")
4545
if exist {
4646
return scw.ParseRegion(rawRegion.(string))
@@ -58,7 +58,7 @@ func ExtractRegion(d terraformResourceData, m interface{}) (scw.Region, error) {
5858
// - region field of the resource data
5959
// - default region given in argument
6060
// - default region from config
61-
func ExtractRegionWithDefault(d terraformResourceData, m interface{}, defaultRegion scw.Region) (scw.Region, error) {
61+
func ExtractRegionWithDefault(d terraformResourceData, m any, defaultRegion scw.Region) (scw.Region, error) {
6262
rawRegion, exist := d.GetOk("region")
6363
if exist {
6464
return scw.ParseRegion(rawRegion.(string))
@@ -79,7 +79,7 @@ func ExtractRegionWithDefault(d terraformResourceData, m interface{}, defaultReg
7979
// ExtractProjectID will try to guess the project id from the following:
8080
// - project_id field of the resource data
8181
// - default project id from config
82-
func ExtractProjectID(d terraformResourceData, m interface{}) (projectID string, isDefault bool, err error) {
82+
func ExtractProjectID(d terraformResourceData, m any) (projectID string, isDefault bool, err error) {
8383
rawProjectID, exist := d.GetOk("project_id")
8484
if exist {
8585
return rawProjectID.(string), false, nil
@@ -93,15 +93,15 @@ func ExtractProjectID(d terraformResourceData, m interface{}) (projectID string,
9393
return "", false, ErrProjectIDNotFound
9494
}
9595

96-
func ExtractScwClient(m interface{}) *scw.Client {
96+
func ExtractScwClient(m any) *scw.Client {
9797
return m.(*Meta).ScwClient()
9898
}
9999

100-
func ExtractHTTPClient(m interface{}) *http.Client {
100+
func ExtractHTTPClient(m any) *http.Client {
101101
return m.(*Meta).HTTPClient()
102102
}
103103

104-
func getKeyInRawConfigMap(rawConfig map[string]cty.Value, key string, ty cty.Type) (interface{}, bool) {
104+
func getKeyInRawConfigMap(rawConfig map[string]cty.Value, key string, ty cty.Type) (any, bool) {
105105
if key == "" {
106106
return rawConfig, false
107107
}
@@ -159,7 +159,7 @@ func getKeyInRawConfigMap(rawConfig map[string]cty.Value, key string, ty cty.Typ
159159

160160
// GetRawConfigForKey returns the value for a specific key in the user's raw configuration, which can be useful on resources' update
161161
// The value for the key to look for must be a primitive type (bool, string, number) and the expected type of the value should be passed as the ty parameter
162-
func GetRawConfigForKey(d *schema.ResourceData, key string, ty cty.Type) (interface{}, bool) {
162+
func GetRawConfigForKey(d *schema.ResourceData, key string, ty cty.Type) (any, bool) {
163163
rawConfig := d.GetRawConfig()
164164
if rawConfig.IsNull() {
165165
return nil, false

internal/provider/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func Provider(config *Config) plugin.ProviderFunc {
341341

342342
addBetaResources(p)
343343

344-
p.ConfigureContextFunc = func(ctx context.Context, data *schema.ResourceData) (interface{}, diag.Diagnostics) {
344+
p.ConfigureContextFunc = func(ctx context.Context, data *schema.ResourceData) (any, diag.Diagnostics) {
345345
terraformVersion := p.TerraformVersion
346346

347347
// If we provide meta in config use it. This is useful for tests

internal/services/account/helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
1111
)
1212

13-
func NewProjectAPI(m interface{}) *accountSDK.ProjectAPI {
13+
func NewProjectAPI(m any) *accountSDK.ProjectAPI {
1414
return accountSDK.NewProjectAPI(meta.ExtractScwClient(m))
1515
}
1616

17-
func GetOrganizationID(m interface{}, d *schema.ResourceData) *string {
17+
func GetOrganizationID(m any, d *schema.ResourceData) *string {
1818
orgID, orgIDExist := d.GetOk("organization_id")
1919

2020
if orgIDExist {

internal/services/account/project.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func ResourceProject() *schema.Resource {
5757
}
5858
}
5959

60-
func resourceAccountProjectCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
60+
func resourceAccountProjectCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
6161
accountAPI := NewProjectAPI(m)
6262

6363
request := &accountSDK.ProjectAPICreateProjectRequest{
@@ -79,7 +79,7 @@ func resourceAccountProjectCreate(ctx context.Context, d *schema.ResourceData, m
7979
return resourceAccountProjectRead(ctx, d, m)
8080
}
8181

82-
func resourceAccountProjectRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
82+
func resourceAccountProjectRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
8383
accountAPI := NewProjectAPI(m)
8484

8585
res, err := accountAPI.GetProject(&accountSDK.ProjectAPIGetProjectRequest{
@@ -104,7 +104,7 @@ func resourceAccountProjectRead(ctx context.Context, d *schema.ResourceData, m i
104104
return nil
105105
}
106106

107-
func resourceAccountProjectUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
107+
func resourceAccountProjectUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
108108
accountAPI := NewProjectAPI(m)
109109

110110
req := &accountSDK.ProjectAPIUpdateProjectRequest{
@@ -133,7 +133,7 @@ func resourceAccountProjectUpdate(ctx context.Context, d *schema.ResourceData, m
133133
return resourceAccountProjectRead(ctx, d, m)
134134
}
135135

136-
func resourceAccountProjectDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
136+
func resourceAccountProjectDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
137137
accountAPI := NewProjectAPI(m)
138138

139139
err := retry.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *retry.RetryError {

0 commit comments

Comments
 (0)