Skip to content

Commit 6b2e258

Browse files
committed
Fixes for release
Closes #69
1 parent 751a0ed commit 6b2e258

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ If you have any feedback, please feel free to open an issue.
1414
## Install
1515

1616
```bash
17-
go get nhooyr.io/websocket
17+
go get nhooyr.io/websocket@0.2.0
1818
```
1919

2020
## Features
@@ -85,9 +85,8 @@ c.Close(websocket.StatusNormalClosure, "")
8585
- Minimal API is easier to maintain and learn
8686
- Context based cancellation is more ergonomic and robust than setting deadlines
8787
- No ping support because TCP keep alives work fine for HTTP/1.1 and they do not make
88-
sense with HTTP/2 (see #1)
89-
- net.Conn is never exposed as WebSocket's over HTTP/2 will not have a net.Conn.
90-
- Structures are nicer than functional options, see [google/go-cloud#908](https://github.com/google/go-cloud/issues/908#issuecomment-445034143)
88+
sense with HTTP/2 (see [#1](https://github.com/nhooyr/websocket/issues/1))
89+
- net.Conn is never exposed as WebSocket over HTTP/2 will not have a net.Conn.
9190
- Using net/http's Client for dialing means we do not have to reinvent dialing hooks
9291
and configurations like other WebSocket libraries
9392

@@ -105,7 +104,7 @@ in production.
105104
https://github.com/gorilla/websocket
106105

107106
This package is the community standard but it is 6 years old and over time
108-
has accumulated cruft. There are many ways to do the same thing, usage is not clear
107+
has accumulated cruft. Using is not clear as there are many ways to do things
109108
and there are some rough edges. Just compare the godoc of
110109
[nhooyr/websocket](https://godoc.org/github.com/nhooyr/websocket) side by side with
111110
[gorilla/websocket](https://godoc.org/github.com/gorilla/websocket).
@@ -115,11 +114,10 @@ which makes it easy to use correctly.
115114

116115
Furthermore, nhooyr/websocket has support for newer Go idioms such as context.Context and
117116
also uses net/http's Client and ResponseWriter directly for WebSocket handshakes.
118-
gorilla/websocket writes its handshakes directly to a net.Conn which means
117+
gorilla/websocket writes its handshakes to the underlying net.Conn which means
119118
it has to reinvent hooks for TLS and proxying and prevents support of HTTP/2.
120119

121-
Another advantage of nhooyr/websocket is that it supports multiple concurrent writers out
122-
of the box.
120+
Another advantage of nhooyr/websocket is that it supports concurrent writers out of the box.
123121

124122
### x/net/websocket
125123

@@ -138,8 +136,9 @@ and clarity.
138136

139137
This library is fantastic in terms of performance. The author put in significant
140138
effort to ensure its speed and I have applied as many of its optimizations as
141-
I could into nhooyr/websocket. Definitely check out his fantastic [blog post](https://medium.freecodecamp.org/million-websockets-and-go-cc58418460bb) about performant WebSocket servers.
139+
I could into nhooyr/websocket. Definitely check out his fantastic [blog post](https://medium.freecodecamp.org/million-websockets-and-go-cc58418460bb)
140+
about performant WebSocket servers.
142141

143142
If you want a library that gives you absolute control over everything, this is the library,
144-
but for most users, the API provided by nhooyr/websocket will fit better as it is just as
145-
performant but much easier to use correctly and idiomatic.
143+
but for most users, the API provided by nhooyr/websocket will fit better as it is nearly just
144+
as performant but much easier to use correctly and idiomatic.

doc.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
//
33
// See https://tools.ietf.org/html/rfc6455
44
//
5-
// Please see https://nhooyr.io/websocket for overview docs and a
6-
// comparison with existing implementations.
7-
//
85
// Conn, Dial, and Accept are the main entrypoints into this package. Use Dial to dial
96
// a WebSocket server, Accept to accept a WebSocket client dial and then Conn to interact
107
// with the resulting WebSocket connections.
118
//
129
// The examples are the best way to understand how to correctly use the library.
1310
//
1411
// The wsjson and wspb subpackages contain helpers for JSON and ProtoBuf messages.
12+
//
13+
// Please see https://nhooyr.io/websocket for more overview docs and a
14+
// comparison with existing implementations.
15+
//
16+
// Please be sure to use the https://golang.org/x/xerrors package when inspecting returned errors.
1517
package websocket

example_echo_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"nhooyr.io/websocket/wsjson"
1717
)
1818

19-
// This example starts a WebSocket echo server and
20-
// then dials the server and sends 5 different messages
19+
// This example starts a WebSocket echo server,
20+
// dials the server and then sends 5 different messages
2121
// and prints out the server's responses.
2222
func Example_echo() {
2323
// First we listen on port 0, that means the OS will

example_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ func ExampleAccept() {
3636
c.Close(websocket.StatusNormalClosure, "")
3737
})
3838

39-
http.ListenAndServe("localhost:8080", fn)
39+
err := http.ListenAndServe("localhost:8080", fn)
40+
log.Fatal(err)
4041
}
4142

4243
// This example dials a server, writes a single JSON message and then
@@ -47,15 +48,13 @@ func ExampleDial() {
4748

4849
c, _, err := websocket.Dial(ctx, "ws://localhost:8080", websocket.DialOptions{})
4950
if err != nil {
50-
log.Println(err)
51-
return
51+
log.Fatal(err)
5252
}
5353
defer c.Close(websocket.StatusInternalError, "the sky is falling")
5454

5555
err = wsjson.Write(ctx, c, "hi")
5656
if err != nil {
57-
log.Println(err)
58-
return
57+
log.Fatal(err)
5958
}
6059

6160
c.Close(websocket.StatusNormalClosure, "")

statuscode.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const (
4242

4343
// CloseError represents a WebSocket close frame.
4444
// It is returned by Conn's methods when the Connection is closed with a WebSocket close frame.
45+
// You will need to use https://golang.org/x/xerrors to check for this error.
4546
type CloseError struct {
4647
Code StatusCode
4748
Reason string

0 commit comments

Comments
 (0)