Skip to content

Commit 9d9c971

Browse files
committed
Update docs
1 parent 50952d7 commit 9d9c971

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@
55

66
websocket is a minimal and idiomatic WebSocket library for Go.
77

8-
> **note**: I haven't been responsive for questions/reports on the issue tracker but I do
9-
> read through and there are no outstanding bugs. There are certainly some nice to haves
10-
> that I should merge in/figure out but nothing critical. I haven't given up on adding new
11-
> features and cleaning up the code further, just been busy. Should anything critical
12-
> arise, I will fix it.
13-
148
## Install
159

16-
```bash
10+
```sh
1711
go get nhooyr.io/websocket
1812
```
1913

@@ -23,18 +17,23 @@ go get nhooyr.io/websocket
2317
- First class [context.Context](https://blog.golang.org/context) support
2418
- Fully passes the WebSocket [autobahn-testsuite](https://github.com/crossbario/autobahn-testsuite)
2519
- [Zero dependencies](https://pkg.go.dev/nhooyr.io/websocket?tab=imports)
26-
- JSON and protobuf helpers in the [wsjson](https://pkg.go.dev/nhooyr.io/websocket/wsjson) and [wspb](https://pkg.go.dev/nhooyr.io/websocket/wspb) subpackages
20+
- JSON helpers in the [wsjson](https://pkg.go.dev/nhooyr.io/websocket/wsjson) subpackage
2721
- Zero alloc reads and writes
2822
- Concurrent writes
2923
- [Close handshake](https://pkg.go.dev/nhooyr.io/websocket#Conn.Close)
3024
- [net.Conn](https://pkg.go.dev/nhooyr.io/websocket#NetConn) wrapper
3125
- [Ping pong](https://pkg.go.dev/nhooyr.io/websocket#Conn.Ping) API
3226
- [RFC 7692](https://tools.ietf.org/html/rfc7692) permessage-deflate compression
27+
- [CloseRead](https://pkg.go.dev/nhooyr.io/websocket#Conn.CloseRead) helper for write only connections
3328
- Compile to [Wasm](https://pkg.go.dev/nhooyr.io/websocket#hdr-Wasm)
3429

3530
## Roadmap
3631

32+
- [ ] Ping pong heartbeat helper [#267](https://github.com/nhooyr/websocket/issues/267)
33+
- [ ] Graceful shutdown helper [#209](https://github.com/nhooyr/websocket/issues/209)
34+
- [ ] Assembly for WebSocket masking [#16](https://github.com/nhooyr/websocket/issues/16)
3735
- [ ] HTTP/2 [#4](https://github.com/nhooyr/websocket/issues/4)
36+
- [ ] The holy grail [#402](https://github.com/nhooyr/websocket/issues/402)
3837

3938
## Examples
4039

@@ -51,7 +50,7 @@ http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
5150
if err != nil {
5251
// ...
5352
}
54-
defer c.Close(websocket.StatusInternalError, "the sky is falling")
53+
defer c.CloseNow()
5554

5655
ctx, cancel := context.WithTimeout(r.Context(), time.Second*10)
5756
defer cancel()
@@ -78,7 +77,7 @@ c, _, err := websocket.Dial(ctx, "ws://localhost:8080", nil)
7877
if err != nil {
7978
// ...
8079
}
81-
defer c.Close(websocket.StatusInternalError, "the sky is falling")
80+
defer c.CloseNow()
8281

8382
err = wsjson.Write(ctx, c, "hi")
8483
if err != nil {
@@ -110,12 +109,14 @@ Advantages of nhooyr.io/websocket:
110109
- Gorilla writes directly to a net.Conn and so duplicates features of net/http.Client.
111110
- Concurrent writes
112111
- Close handshake ([gorilla/websocket#448](https://github.com/gorilla/websocket/issues/448))
112+
- [CloseRead](https://pkg.go.dev/nhooyr.io/websocket#Conn.CloseRead) helper for write only connections
113113
- Idiomatic [ping pong](https://pkg.go.dev/nhooyr.io/websocket#Conn.Ping) API
114114
- Gorilla requires registering a pong callback before sending a Ping
115115
- Can target Wasm ([gorilla/websocket#432](https://github.com/gorilla/websocket/issues/432))
116-
- Transparent message buffer reuse with [wsjson](https://pkg.go.dev/nhooyr.io/websocket/wsjson) and [wspb](https://pkg.go.dev/nhooyr.io/websocket/wspb) subpackages
116+
- Transparent message buffer reuse with [wsjson](https://pkg.go.dev/nhooyr.io/websocket/wsjson) subpackage
117117
- [1.75x](https://github.com/nhooyr/websocket/releases/tag/v1.7.4) faster WebSocket masking implementation in pure Go
118118
- Gorilla's implementation is slower and uses [unsafe](https://golang.org/pkg/unsafe/).
119+
Soon we'll have assembly and be 4.5x faster [#326](https://github.com/nhooyr/websocket/pull/326)
119120
- Full [permessage-deflate](https://tools.ietf.org/html/rfc7692) compression extension support
120121
- Gorilla only supports no context takeover mode
121122
- [CloseRead](https://pkg.go.dev/nhooyr.io/websocket#Conn.CloseRead) helper ([gorilla/websocket#492](https://github.com/gorilla/websocket/issues/492))

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//
1414
// The examples are the best way to understand how to correctly use the library.
1515
//
16-
// The wsjson and wspb subpackages contain helpers for JSON and protobuf messages.
16+
// The wsjson subpackage contain helpers for JSON and protobuf messages.
1717
//
1818
// More documentation at https://nhooyr.io/websocket.
1919
//

example_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func ExampleAccept() {
2020
log.Println(err)
2121
return
2222
}
23-
defer c.Close(websocket.StatusInternalError, "the sky is falling")
23+
defer c.CloseNow()
2424

2525
ctx, cancel := context.WithTimeout(r.Context(), time.Second*10)
2626
defer cancel()
@@ -50,7 +50,7 @@ func ExampleDial() {
5050
if err != nil {
5151
log.Fatal(err)
5252
}
53-
defer c.Close(websocket.StatusInternalError, "the sky is falling")
53+
defer c.CloseNow()
5454

5555
err = wsjson.Write(ctx, c, "hi")
5656
if err != nil {
@@ -71,7 +71,7 @@ func ExampleCloseStatus() {
7171
if err != nil {
7272
log.Fatal(err)
7373
}
74-
defer c.Close(websocket.StatusInternalError, "the sky is falling")
74+
defer c.CloseNow()
7575

7676
_, _, err = c.Reader(ctx)
7777
if websocket.CloseStatus(err) != websocket.StatusNormalClosure {
@@ -88,7 +88,7 @@ func Example_writeOnly() {
8888
log.Println(err)
8989
return
9090
}
91-
defer c.Close(websocket.StatusInternalError, "the sky is falling")
91+
defer c.CloseNow()
9292

9393
ctx, cancel := context.WithTimeout(r.Context(), time.Minute*10)
9494
defer cancel()
@@ -145,7 +145,7 @@ func ExampleConn_Ping() {
145145
if err != nil {
146146
log.Fatal(err)
147147
}
148-
defer c.Close(websocket.StatusInternalError, "the sky is falling")
148+
defer c.CloseNow()
149149

150150
// Required to read the Pongs from the server.
151151
ctx = c.CloseRead(ctx)
@@ -162,10 +162,10 @@ func ExampleConn_Ping() {
162162

163163
// This example demonstrates full stack chat with an automated test.
164164
func Example_fullStackChat() {
165-
// https://github.com/nhooyr/websocket/tree/master/examples/chat
165+
// https://github.com/nhooyr/websocket/tree/master/internal/examples/chat
166166
}
167167

168168
// This example demonstrates a echo server.
169169
func Example_echo() {
170-
// https://github.com/nhooyr/websocket/tree/master/examples/echo
170+
// https://github.com/nhooyr/websocket/tree/master/internal/examples/echo
171171
}

internal/examples/chat/chat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (cs *chatServer) subscribeHandler(w http.ResponseWriter, r *http.Request) {
7474
cs.logf("%v", err)
7575
return
7676
}
77-
defer c.Close(websocket.StatusInternalError, "")
77+
defer c.CloseNow()
7878

7979
err = cs.subscribe(r.Context(), c)
8080
if errors.Is(err, context.Canceled) {

internal/examples/echo/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (s echoServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
2828
s.logf("%v", err)
2929
return
3030
}
31-
defer c.Close(websocket.StatusInternalError, "the sky is falling")
31+
defer c.CloseNow()
3232

3333
if c.Subprotocol() != "echo" {
3434
c.Close(websocket.StatusPolicyViolation, "client must speak the echo subprotocol")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy