Skip to content

Commit 61efa3c

Browse files
committed
Improve API brevity
1 parent 9f4fb59 commit 61efa3c

File tree

6 files changed

+13
-12
lines changed

6 files changed

+13
-12
lines changed

example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ func ExampleAccept_echo() {
2929
ctx, cancel := context.WithTimeout(ctx, time.Minute)
3030
defer cancel()
3131

32-
typ, r, err := c.ReadMessage(ctx)
32+
typ, r, err := c.Read(ctx)
3333
if err != nil {
3434
return err
3535
}
3636

3737
r = io.LimitReader(r, 32768)
3838

39-
w := c.MessageWriter(ctx, typ)
39+
w := c.Write(ctx, typ)
4040
_, err = io.Copy(w, r)
4141
if err != nil {
4242
return err

header_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func randBool() bool {
1919

2020
func TestHeader(t *testing.T) {
2121
t.Parallel()
22-
22+
2323
t.Run("negative", func(t *testing.T) {
2424
t.Parallel()
2525

json.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
// JSONConn wraps around a Conn with JSON helpers.
1212
type JSONConn struct {
13-
Conn *Conn
13+
*Conn
1414
}
1515

1616
// Read reads a json message into v.
@@ -23,7 +23,7 @@ func (jc JSONConn) Read(ctx context.Context, v interface{}) error {
2323
}
2424

2525
func (jc *JSONConn) read(ctx context.Context, v interface{}) error {
26-
typ, r, err := jc.Conn.ReadMessage(ctx)
26+
typ, r, err := jc.Conn.Read(ctx)
2727
if err != nil {
2828
return err
2929
}
@@ -52,7 +52,7 @@ func (jc JSONConn) Write(ctx context.Context, v interface{}) error {
5252
}
5353

5454
func (jc JSONConn) write(ctx context.Context, v interface{}) error {
55-
w := jc.Conn.MessageWriter(ctx, DataText)
55+
w := jc.Conn.Write(ctx, DataText)
5656

5757
e := json.NewEncoder(w)
5858
err := e.Encode(v)

test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function docker_run() {
1010
local IMAGE
1111
IMAGE="$(docker build -q "$DIR")"
1212
docker run \
13+
-it \
1314
-v "${PWD}:/repo" \
1415
-v "$(go env GOPATH):/go" \
1516
-v "$(go env GOCACHE):/root/.cache/go-build" \

websocket.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,11 @@ func (c *Conn) writeControl(ctx context.Context, opcode opcode, p []byte) error
401401
}
402402
}
403403

404-
// MessageWriter returns a writer bounded by the context that will write
404+
// Write returns a writer bounded by the context that will write
405405
// a WebSocket data frame of type dataType to the connection.
406406
// Ensure you close the messageWriter once you have written to entire message.
407407
// Concurrent calls to messageWriter are ok.
408-
func (c *Conn) MessageWriter(ctx context.Context, dataType DataType) io.WriteCloser {
408+
func (c *Conn) Write(ctx context.Context, dataType DataType) io.WriteCloser {
409409
return &messageWriter{
410410
c: c,
411411
ctx: ctx,
@@ -487,7 +487,7 @@ func (w *messageWriter) Close() error {
487487
// Please use SetContext on the reader to bound the read operation.
488488
// Your application must keep reading messages for the Conn to automatically respond to ping
489489
// and close frames.
490-
func (c *Conn) ReadMessage(ctx context.Context) (DataType, io.Reader, error) {
490+
func (c *Conn) Read(ctx context.Context) (DataType, io.Reader, error) {
491491
select {
492492
case <-c.closed:
493493
return 0, nil, xerrors.Errorf("failed to read message: %w", c.getCloseErr())

websocket_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,12 @@ func echoLoop(ctx context.Context, c *websocket.Conn, t *testing.T) {
360360
ctx, cancel := context.WithTimeout(ctx, time.Minute)
361361
defer cancel()
362362

363-
typ, r, err := c.ReadMessage(ctx)
363+
typ, r, err := c.Read(ctx)
364364
if err != nil {
365365
return err
366366
}
367367

368-
w := c.MessageWriter(ctx, typ)
368+
w := c.Write(ctx, typ)
369369

370370
_, err = io.Copy(w, r)
371371
if err != nil {
@@ -447,7 +447,7 @@ func TestAutobahnClient(t *testing.T) {
447447
}
448448
defer c.Close(websocket.StatusInternalError, "")
449449

450-
_, r, err := c.ReadMessage(ctx)
450+
_, r, err := c.Read(ctx)
451451
if err != nil {
452452
t.Fatal(err)
453453
}

0 commit comments

Comments
 (0)