Skip to content

Commit 65a6800

Browse files
committed
Use any instead of interface{} given Go > 1.18
1 parent efb626b commit 65a6800

File tree

11 files changed

+21
-21
lines changed

11 files changed

+21
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
6868
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
6969
defer cancel()
7070

71-
var v interface{}
71+
var v any
7272
err = wsjson.Read(ctx, c, &v)
7373
if err != nil {
7474
// ...

autobahn_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func wstestServer(tb testing.TB, ctx context.Context) (url string, closeFn func(
130130
url = "ws://" + serverAddr
131131
const outDir = "ci/out/autobahn-report"
132132

133-
specFile, err := tempJSONFile(map[string]interface{}{
133+
specFile, err := tempJSONFile(map[string]any{
134134
"url": url,
135135
"outdir": outDir,
136136
"cases": autobahnCases,
@@ -280,7 +280,7 @@ func unusedListenAddr() (_ string, err error) {
280280
return l.Addr().String(), nil
281281
}
282282

283-
func tempJSONFile(v interface{}) (string, error) {
283+
func tempJSONFile(v any) (string, error) {
284284
f, err := os.CreateTemp("", "temp.json")
285285
if err != nil {
286286
return "", fmt.Errorf("temp file: %w", err)

conn_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func TestConn(t *testing.T) {
341341
return wsjson.Write(tt.ctx, c1, exp)
342342
})
343343

344-
var act interface{}
344+
var act any
345345
err := wsjson.Read(tt.ctx, c1, &act)
346346
assert.Success(t, err)
347347
assert.Equal(t, "read msg", exp, act)
@@ -372,7 +372,7 @@ func TestConn(t *testing.T) {
372372
return wsjson.Write(tt.ctx, c1, exp)
373373
})
374374

375-
var act interface{}
375+
var act any
376376
err := wsjson.Read(tt.ctx, c1, &act)
377377
assert.Success(t, err)
378378
assert.Equal(t, "read msg", exp, act)
@@ -660,7 +660,7 @@ func assertEcho(tb testing.TB, ctx context.Context, c *websocket.Conn) {
660660
return wsjson.Write(ctx, c, exp)
661661
})
662662

663-
var act interface{}
663+
var act any
664664
c.SetReadLimit(1 << 30)
665665
err := wsjson.Read(ctx, c, &act)
666666
assert.Success(tb, err)

example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func ExampleAccept() {
2525
ctx, cancel := context.WithTimeout(r.Context(), time.Second*10)
2626
defer cancel()
2727

28-
var v interface{}
28+
var v any
2929
err = wsjson.Read(ctx, c, &v)
3030
if err != nil {
3131
log.Println(err)

internal/errd/wrap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
// Wrap wraps err with fmt.Errorf if err is non nil.
88
// Intended for use with defer and a named error return.
99
// Inspired by https://github.com/golang/go/issues/32676.
10-
func Wrap(err *error, f string, v ...interface{}) {
10+
func Wrap(err *error, f string, v ...any) {
1111
if *err != nil {
1212
*err = fmt.Errorf(f+": %w", append(v, *err)...)
1313
}

internal/examples/chat/chat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type chatServer struct {
3131

3232
// logf controls where logs are sent.
3333
// Defaults to log.Printf.
34-
logf func(f string, v ...interface{})
34+
logf func(f string, v ...any)
3535

3636
// serveMux routes the various endpoints to the appropriate handler.
3737
serveMux http.ServeMux

internal/examples/echo/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
// only allows one message every 100ms with a 10 message burst.
1818
type echoServer struct {
1919
// logf controls where logs are sent.
20-
logf func(f string, v ...interface{})
20+
logf func(f string, v ...any)
2121
}
2222

2323
func (s echoServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {

internal/test/assert/assert.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
// Equal asserts exp == act.
12-
func Equal(t testing.TB, name string, exp, got interface{}) {
12+
func Equal(t testing.TB, name string, exp, got any) {
1313
t.Helper()
1414

1515
if !reflect.DeepEqual(exp, got) {
@@ -36,7 +36,7 @@ func Error(t testing.TB, err error) {
3636
}
3737

3838
// Contains asserts the fmt.Sprint(v) contains sub.
39-
func Contains(t testing.TB, v interface{}, sub string) {
39+
func Contains(t testing.TB, v any, sub string) {
4040
t.Helper()
4141

4242
s := fmt.Sprint(v)

internal/thirdparty/gin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestGin(t *testing.T) {
4242
err = wsjson.Write(ctx, c, "hello")
4343
assert.Success(t, err)
4444

45-
var v interface{}
45+
var v any
4646
err = wsjson.Read(ctx, c, &v)
4747
assert.Success(t, err)
4848
assert.Equal(t, "read msg", "hello", v)

internal/wsjs/wsjs_js.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func New(url string, protocols []string) (c WebSocket, err error) {
3333
c = WebSocket{}
3434
})
3535

36-
jsProtocols := make([]interface{}, len(protocols))
36+
jsProtocols := make([]any, len(protocols))
3737
for i, p := range protocols {
3838
jsProtocols[i] = p
3939
}
@@ -57,7 +57,7 @@ func (c WebSocket) setBinaryType(typ string) {
5757
}
5858

5959
func (c WebSocket) addEventListener(eventType string, fn func(e js.Value)) func() {
60-
f := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
60+
f := js.FuncOf(func(this js.Value, args []js.Value) any {
6161
fn(args[0])
6262
return nil
6363
})
@@ -97,7 +97,7 @@ func (c WebSocket) OnError(fn func(e js.Value)) (remove func()) {
9797
// MessageEvent is the type passed to a message handler.
9898
type MessageEvent struct {
9999
// string or []byte.
100-
Data interface{}
100+
Data any
101101

102102
// There are more fields to the interface but we don't use them.
103103
// See https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
@@ -106,7 +106,7 @@ type MessageEvent struct {
106106
// OnMessage registers a function to be called when the WebSocket receives a message.
107107
func (c WebSocket) OnMessage(fn func(m MessageEvent)) (remove func()) {
108108
return c.addEventListener("message", func(e js.Value) {
109-
var data interface{}
109+
var data any
110110

111111
arrayBuffer := e.Get("data")
112112
if arrayBuffer.Type() == js.TypeString {

0 commit comments

Comments
 (0)