Skip to content

Commit c8f8d29

Browse files
authored
Merge pull request #256 from nhooyr/dev
v1.8.8
2 parents 14fb98e + af0fd9d commit c8f8d29

Some content is hidden

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

72 files changed

+2744
-1664
lines changed

.github/CODEOWNERS

-1
This file was deleted.

.github/workflows/ci.yaml

-39
This file was deleted.

.github/workflows/ci.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: ci
2+
on: [push, pull_request]
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
5+
cancel-in-progress: true
6+
7+
jobs:
8+
fmt:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-go@v4
13+
with:
14+
go-version-file: ./go.mod
15+
- run: ./ci/fmt.sh
16+
17+
lint:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
- run: go version
22+
- uses: actions/setup-go@v4
23+
with:
24+
go-version-file: ./go.mod
25+
- run: ./ci/lint.sh
26+
27+
test:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v4
31+
- uses: actions/setup-go@v4
32+
with:
33+
go-version-file: ./go.mod
34+
- run: ./ci/test.sh
35+
- uses: actions/upload-artifact@v3
36+
with:
37+
name: coverage.html
38+
path: ./ci/out/coverage.html
39+
40+
bench:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v4
44+
- uses: actions/setup-go@v4
45+
with:
46+
go-version-file: ./go.mod
47+
- run: ./ci/bench.sh

.github/workflows/daily.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: daily
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: '42 0 * * *' # daily at 00:42
6+
concurrency:
7+
group: ${{ github.workflow }}
8+
cancel-in-progress: true
9+
10+
jobs:
11+
bench:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-go@v4
16+
with:
17+
go-version-file: ./go.mod
18+
- run: AUTOBAHN=1 ./ci/bench.sh
19+
test:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: actions/setup-go@v4
24+
with:
25+
go-version-file: ./go.mod
26+
- run: AUTOBAHN=1 ./ci/test.sh
27+
- uses: actions/upload-artifact@v3
28+
with:
29+
name: coverage.html
30+
path: ./ci/out/coverage.html
31+
bench-dev:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
with:
36+
ref: dev
37+
- uses: actions/setup-go@v4
38+
with:
39+
go-version-file: ./go.mod
40+
- run: AUTOBAHN=1 ./ci/bench.sh
41+
test-dev:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v4
45+
with:
46+
ref: dev
47+
- uses: actions/setup-go@v4
48+
with:
49+
go-version-file: ./go.mod
50+
- run: AUTOBAHN=1 ./ci/test.sh
51+
- uses: actions/upload-artifact@v3
52+
with:
53+
name: coverage.html
54+
path: ./ci/out/coverage.html

.gitignore

-1
This file was deleted.

LICENSE.txt

+13-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
MIT License
2-
3-
Copyright (c) 2018 Anmol Sethi
4-
5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
11-
12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
14-
15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
1+
Copyright (c) 2023 Anmol Sethi <[email protected]>
2+
3+
Permission to use, copy, modify, and distribute this software for any
4+
purpose with or without fee is hereby granted, provided that the above
5+
copyright notice and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

README.md

+34-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
# websocket
22

33
[![godoc](https://godoc.org/nhooyr.io/websocket?status.svg)](https://pkg.go.dev/nhooyr.io/websocket)
4-
[![coverage](https://img.shields.io/badge/coverage-88%25-success)](https://nhooyrio-websocket-coverage.netlify.app)
4+
[![coverage](https://img.shields.io/badge/coverage-91%25-success)](https://nhooyr.io/websocket/coverage.html)
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

@@ -22,26 +16,37 @@ go get nhooyr.io/websocket
2216
- Minimal and idiomatic API
2317
- First class [context.Context](https://blog.golang.org/context) support
2418
- Fully passes the WebSocket [autobahn-testsuite](https://github.com/crossbario/autobahn-testsuite)
25-
- [Single dependency](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
19+
- [Zero dependencies](https://pkg.go.dev/nhooyr.io/websocket?tab=imports)
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+
See GitHub issues for minor issues but the major future enhancements are:
33+
34+
- [ ] Perfect examples [#217](https://github.com/nhooyr/websocket/issues/217)
35+
- [ ] wstest.Pipe for in memory testing [#340](https://github.com/nhooyr/websocket/issues/340)
36+
- [ ] Ping pong heartbeat helper [#267](https://github.com/nhooyr/websocket/issues/267)
37+
- [ ] Ping pong instrumentation callbacks [#246](https://github.com/nhooyr/websocket/issues/246)
38+
- [ ] Graceful shutdown helpers [#209](https://github.com/nhooyr/websocket/issues/209)
39+
- [ ] Assembly for WebSocket masking [#16](https://github.com/nhooyr/websocket/issues/16)
40+
- WIP at [#326](https://github.com/nhooyr/websocket/pull/326), about 3x faster
3741
- [ ] HTTP/2 [#4](https://github.com/nhooyr/websocket/issues/4)
42+
- [ ] The holy grail [#402](https://github.com/nhooyr/websocket/issues/402)
3843

3944
## Examples
4045

4146
For a production quality example that demonstrates the complete API, see the
42-
[echo example](./examples/echo).
47+
[echo example](./internal/examples/echo).
4348

44-
For a full stack example, see the [chat example](./examples/chat).
49+
For a full stack example, see the [chat example](./internal/examples/chat).
4550

4651
### Server
4752

@@ -51,7 +56,7 @@ http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
5156
if err != nil {
5257
// ...
5358
}
54-
defer c.Close(websocket.StatusInternalError, "the sky is falling")
59+
defer c.CloseNow()
5560

5661
ctx, cancel := context.WithTimeout(r.Context(), time.Second*10)
5762
defer cancel()
@@ -78,7 +83,7 @@ c, _, err := websocket.Dial(ctx, "ws://localhost:8080", nil)
7883
if err != nil {
7984
// ...
8085
}
81-
defer c.Close(websocket.StatusInternalError, "the sky is falling")
86+
defer c.CloseNow()
8287

8388
err = wsjson.Write(ctx, c, "hi")
8489
if err != nil {
@@ -113,14 +118,13 @@ Advantages of nhooyr.io/websocket:
113118
- Idiomatic [ping pong](https://pkg.go.dev/nhooyr.io/websocket#Conn.Ping) API
114119
- Gorilla requires registering a pong callback before sending a Ping
115120
- 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
121+
- Transparent message buffer reuse with [wsjson](https://pkg.go.dev/nhooyr.io/websocket/wsjson) subpackage
117122
- [1.75x](https://github.com/nhooyr/websocket/releases/tag/v1.7.4) faster WebSocket masking implementation in pure Go
118123
- Gorilla's implementation is slower and uses [unsafe](https://golang.org/pkg/unsafe/).
124+
Soon we'll have assembly and be 3x faster [#326](https://github.com/nhooyr/websocket/pull/326)
119125
- Full [permessage-deflate](https://tools.ietf.org/html/rfc7692) compression extension support
120126
- Gorilla only supports no context takeover mode
121-
- We use [klauspost/compress](https://github.com/klauspost/compress) for much lower memory usage ([gorilla/websocket#203](https://github.com/gorilla/websocket/issues/203))
122-
- [CloseRead](https://pkg.go.dev/nhooyr.io/websocket#Conn.CloseRead) helper ([gorilla/websocket#492](https://github.com/gorilla/websocket/issues/492))
123-
- Actively maintained ([gorilla/websocket#370](https://github.com/gorilla/websocket/issues/370))
127+
- [CloseRead](https://pkg.go.dev/nhooyr.io/websocket#Conn.CloseRead) helper for write only connections ([gorilla/websocket#492](https://github.com/gorilla/websocket/issues/492))
124128

125129
#### golang.org/x/net/websocket
126130

@@ -135,4 +139,15 @@ to nhooyr.io/websocket.
135139
[gobwas/ws](https://github.com/gobwas/ws) has an extremely flexible API that allows it to be used
136140
in an event driven style for performance. See the author's [blog post](https://medium.freecodecamp.org/million-websockets-and-go-cc58418460bb).
137141

138-
However when writing idiomatic Go, nhooyr.io/websocket will be faster and easier to use.
142+
However it is quite bloated. See https://pkg.go.dev/github.com/gobwas/ws
143+
144+
When writing idiomatic Go, nhooyr.io/websocket will be faster and easier to use.
145+
146+
#### lesismal/nbio
147+
148+
[lesismal/nbio](https://github.com/lesismal/nbio) is similar to gobwas/ws in that the API is
149+
event driven for performance reasons.
150+
151+
However it is quite bloated. See https://pkg.go.dev/github.com/lesismal/nbio
152+
153+
When writing idiomatic Go, nhooyr.io/websocket will be faster and easier to use.

0 commit comments

Comments
 (0)