Skip to content

Commit a9965fb

Browse files
authored
refactor: use 'any' instead of 'interface{}' for consistency (#3090)
1 parent d5c9f89 commit a9965fb

File tree

126 files changed

+474
-466
lines changed

Some content is hidden

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

126 files changed

+474
-466
lines changed

‎.golangci.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ linters-settings:
1111
enable-all-rules: false
1212
rules:
1313
- name: empty-lines
14+
- name: use-any
1415
testifylint:
1516
disable-all: true
1617
enable:
@@ -52,3 +53,10 @@ issues:
5253
linters:
5354
- dupl
5455
- errcheck
56+
# Disable revive.use-any for backwards compatibility
57+
- path: graphql/map.go
58+
text: "use-any: since GO 1.18 'interface{}' can be replaced by 'any'"
59+
- path: codegen/testserver/followschema/resolver.go
60+
text: "use-any: since GO 1.18 'interface{}' can be replaced by 'any'"
61+
- path: codegen/testserver/singlefile/resolver.go
62+
text: "use-any: since GO 1.18 'interface{}' can be replaced by 'any'"

‎_examples/chat/chat_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestChatSubscriptions(t *testing.T) {
4444
require.Equal(t, "system", msg.resp.MessageAdded.CreatedBy)
4545

4646
go func() {
47-
var resp interface{}
47+
var resp any
4848
err := c.Post(fmt.Sprintf(`mutation {
4949
a:post(text:"Hello!", roomName:"#gophers%d", username:"vektah") { id }
5050
b:post(text:"Hello Vektah!", roomName:"#gophers%d", username:"andrey") { id }

‎_examples/chat/resolvers.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func New() Config {
3535
Rooms: sync.Map{},
3636
},
3737
Directives: DirectiveRoot{
38-
User: func(ctx context.Context, obj interface{}, next graphql.Resolver, username string) (res interface{}, err error) {
38+
User: func(ctx context.Context, obj any, next graphql.Resolver, username string) (res any, err error) {
3939
return next(context.WithValue(ctx, ckey("username"), username))
4040
},
4141
},
@@ -73,7 +73,7 @@ func (r *mutationResolver) Post(ctx context.Context, text string, username strin
7373
}
7474

7575
room.Messages = append(room.Messages, *message)
76-
room.Observers.Range(func(_, v interface{}) bool {
76+
room.Observers.Range(func(_, v any) bool {
7777
observer := v.(*Observer)
7878
if observer.Username == "" || observer.Username == message.CreatedBy {
7979
observer.Message <- message

‎_examples/dataloader/dataloader_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestTodo(t *testing.T) {
1414
c := client.New(LoaderMiddleware(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: &Resolver{}}))))
1515

1616
t.Run("create a new todo", func(t *testing.T) {
17-
var resp interface{}
17+
var resp any
1818
c.MustPost(`{
1919
customers {
2020
name
@@ -73,7 +73,7 @@ func TestTodo(t *testing.T) {
7373

7474
t.Run("introspection", func(t *testing.T) {
7575
// Make sure we can run the graphiql introspection query without errors
76-
var resp interface{}
76+
var resp any
7777
c.MustPost(introspection.Query, &resp)
7878
})
7979

‎_examples/fileupload/fileupload_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestFileUpload(t *testing.T) {
9999
SingleUploadWithPayload *model.File
100100
}
101101

102-
err := gql.Post(mutation, &result, gqlclient.Var("req", map[string]interface{}{"id": 1, "file": aTxtFile}), gqlclient.WithFiles())
102+
err := gql.Post(mutation, &result, gqlclient.Var("req", map[string]any{"id": 1, "file": aTxtFile}), gqlclient.WithFiles())
103103
require.NoError(t, err)
104104
require.Equal(t, 1, result.SingleUploadWithPayload.ID)
105105
require.Contains(t, result.SingleUploadWithPayload.Name, "a.txt")
@@ -192,7 +192,7 @@ func TestFileUpload(t *testing.T) {
192192
MultipleUploadWithPayload []*model.File
193193
}
194194

195-
err := gql.Post(mutation, &result, gqlclient.Var("req", []map[string]interface{}{
195+
err := gql.Post(mutation, &result, gqlclient.Var("req", []map[string]any{
196196
{"id": 1, "file": a1TxtFile},
197197
{"id": 2, "file": b1TxtFile},
198198
}), gqlclient.WithFiles())
@@ -267,7 +267,7 @@ func TestFileUpload(t *testing.T) {
267267
MultipleUploadWithPayload []*model.File
268268
}
269269

270-
err := gql.Post(mutation, &result, gqlclient.Var("req", []map[string]interface{}{
270+
err := gql.Post(mutation, &result, gqlclient.Var("req", []map[string]any{
271271
{"id": 1, "file": a1TxtFile},
272272
{"id": 2, "file": a1TxtFile},
273273
}), gqlclient.WithFiles())

‎_examples/scalars/model/model.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (b Banned) MarshalGQL(w io.Writer) {
2222
}
2323
}
2424

25-
func (b *Banned) UnmarshalGQL(v interface{}) error {
25+
func (b *Banned) UnmarshalGQL(v any) error {
2626
switch v := v.(type) {
2727
case string:
2828
*b = strings.ToLower(v) == "true"
@@ -53,7 +53,7 @@ type Point struct {
5353
Y int
5454
}
5555

56-
func (p *Point) UnmarshalGQL(v interface{}) error {
56+
func (p *Point) UnmarshalGQL(v any) error {
5757
pointStr, ok := v.(string)
5858
if !ok {
5959
return fmt.Errorf("points must be strings")
@@ -90,7 +90,7 @@ func MarshalTimestamp(t time.Time) graphql.Marshaler {
9090

9191
// Unmarshal{Typename} is only required if the scalar appears as an input. The raw values have already been decoded
9292
// from json into int/float64/bool/nil/map[string]interface/[]interface
93-
func UnmarshalTimestamp(v interface{}) (time.Time, error) {
93+
func UnmarshalTimestamp(v any) (time.Time, error) {
9494
if tmpStr, ok := v.(int64); ok {
9595
return time.Unix(tmpStr, 0), nil
9696
}
@@ -105,7 +105,7 @@ func MarshalID(id external.ObjectID) graphql.Marshaler {
105105
}
106106

107107
// And the same for the unmarshaler
108-
func UnmarshalID(v interface{}) (external.ObjectID, error) {
108+
func UnmarshalID(v any) (external.ObjectID, error) {
109109
str, ok := v.(string)
110110
if !ok {
111111
return 0, fmt.Errorf("ids must be strings")
@@ -163,7 +163,7 @@ func (e Tier) String() string {
163163
}
164164
}
165165

166-
func (e *Tier) UnmarshalGQL(v interface{}) error {
166+
func (e *Tier) UnmarshalGQL(v any) error {
167167
str, ok := v.(string)
168168
if !ok {
169169
return fmt.Errorf("enums must be strings")
@@ -186,7 +186,7 @@ func MarshalPreferences(p *Prefs) graphql.Marshaler {
186186
return graphql.MarshalBoolean(p.DarkMode)
187187
}
188188

189-
func UnmarshalPreferences(v interface{}) (*Prefs, error) {
189+
func UnmarshalPreferences(v any) (*Prefs, error) {
190190
tmp, err := graphql.UnmarshalBoolean(v)
191191
if err != nil {
192192
return nil, err

‎_examples/scalars/scalar_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestScalars(t *testing.T) {
7373

7474
t.Run("introspection", func(t *testing.T) {
7575
// Make sure we can run the graphiql introspection query without errors
76-
var resp interface{}
76+
var resp any
7777
c.MustPost(introspection.Query, &resp)
7878
})
7979
}

‎_examples/starwars/server/server.go‎

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

1616
func main() {
1717
srv := handler.NewDefaultServer(generated.NewExecutableSchema(starwars.NewResolver()))
18-
srv.AroundFields(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) {
18+
srv.AroundFields(func(ctx context.Context, next graphql.Resolver) (res any, err error) {
1919
rc := graphql.GetFieldContext(ctx)
2020
fmt.Println("Entered", rc.Object, rc.Field.Name)
2121
res, err = next(ctx)

‎_examples/starwars/starwars_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func TestStarwars(t *testing.T) {
220220

221221
t.Run("introspection", func(t *testing.T) {
222222
// Make sure we can run the graphiql introspection query without errors
223-
var resp interface{}
223+
var resp any
224224
c.MustPost(introspection.Query, &resp)
225225
})
226226

‎_examples/todo/server/server.go‎

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

1515
func main() {
1616
srv := handler.NewDefaultServer(todo.NewExecutableSchema(todo.New()))
17-
srv.SetRecoverFunc(func(ctx context.Context, err interface{}) (userMessage error) {
17+
srv.SetRecoverFunc(func(ctx context.Context, err any) (userMessage error) {
1818
// send this panic somewhere
1919
log.Print(err)
2020
debug.PrintStack()

0 commit comments

Comments
 (0)