Skip to content

Commit 0978a2f

Browse files
authored
Merge branch 'master' into dev
2 parents 35fb753 + b366270 commit 0978a2f

39 files changed

+161
-100
lines changed

Diff for: .github/workflows/ci.yml

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ jobs:
2020
- uses: actions/checkout@v4
2121
- run: go version
2222
- uses: actions/setup-go@v5
23-
with:
24-
go-version-file: ./go.mod
2523
- run: ./ci/lint.sh
2624

2725
test:

Diff for: .github/workflows/static.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: static
2+
3+
on:
4+
push:
5+
branches: ['master']
6+
workflow_dispatch:
7+
8+
# Set permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages.
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: pages
16+
cancel-in-progress: true
17+
18+
jobs:
19+
deploy:
20+
environment:
21+
name: github-pages
22+
url: ${{ steps.deployment.outputs.page_url }}
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
- name: Setup Pages
28+
uses: actions/configure-pages@v5
29+
- name: Setup Go
30+
uses: actions/setup-go@v5
31+
with:
32+
go-version-file: ./go.mod
33+
- name: Generate coverage and badge
34+
run: |
35+
./ci/test.sh
36+
mkdir -p ./ci/out/static
37+
cp ./ci/out/coverage.html ./ci/out/static/coverage.html
38+
percent=$(go tool cover -func ./ci/out/coverage.prof | tail -n1 | awk '{print $3}' | tr -d '%')
39+
wget -O ./ci/out/static/coverage.svg "https://img.shields.io/badge/coverage-${percent}%25-success"
40+
- name: Upload artifact
41+
uses: actions/upload-pages-artifact@v3
42+
with:
43+
path: ./ci/out/static/
44+
- name: Deploy to GitHub Pages
45+
id: deployment
46+
uses: actions/deploy-pages@v4

Diff for: README.md

+26-21
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
# websocket
22

3-
[![Go Reference](https://pkg.go.dev/badge/nhooyr.io/websocket.svg)](https://pkg.go.dev/nhooyr.io/websocket)
4-
[![Go Coverage](https://img.shields.io/badge/coverage-91%25-success)](https://nhooyr.io/websocket/coverage.html)
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/coder/websocket.svg)](https://pkg.go.dev/github.com/coder/websocket)
4+
[![Go Coverage](https://coder.github.io/websocket/coverage.svg)](https://coder.github.io/websocket/coverage.html)
55

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

88
## Install
99

1010
```sh
11-
go get nhooyr.io/websocket
11+
go get github.com/coder/websocket
1212
```
1313

14+
> [!NOTE]
15+
> Coder now maintains this project as explained in [this blog post](https://coder.com/blog/websocket).
16+
> We're grateful to [nhooyr](https://github.com/nhooyr) for authoring and maintaining this project from
17+
> 2019 to 2024.
18+
1419
## Highlights
1520

1621
- Minimal and idiomatic API
1722
- First class [context.Context](https://blog.golang.org/context) support
1823
- Fully passes the WebSocket [autobahn-testsuite](https://github.com/crossbario/autobahn-testsuite)
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
24+
- [Zero dependencies](https://pkg.go.dev/github.com/coder/websocket?tab=imports)
25+
- JSON helpers in the [wsjson](https://pkg.go.dev/github.com/coder/websocket/wsjson) subpackage
2126
- Zero alloc reads and writes
2227
- Concurrent writes
23-
- [Close handshake](https://pkg.go.dev/nhooyr.io/websocket#Conn.Close)
24-
- [net.Conn](https://pkg.go.dev/nhooyr.io/websocket#NetConn) wrapper
25-
- [Ping pong](https://pkg.go.dev/nhooyr.io/websocket#Conn.Ping) API
28+
- [Close handshake](https://pkg.go.dev/github.com/coder/websocket#Conn.Close)
29+
- [net.Conn](https://pkg.go.dev/github.com/coder/websocket#NetConn) wrapper
30+
- [Ping pong](https://pkg.go.dev/github.com/coder/websocket#Conn.Ping) API
2631
- [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
28-
- Compile to [Wasm](https://pkg.go.dev/nhooyr.io/websocket#hdr-Wasm)
32+
- [CloseRead](https://pkg.go.dev/github.com/coder/websocket#Conn.CloseRead) helper for write only connections
33+
- Compile to [Wasm](https://pkg.go.dev/github.com/coder/websocket#hdr-Wasm)
2934

3035
## Roadmap
3136

@@ -102,39 +107,39 @@ Advantages of [gorilla/websocket](https://github.com/gorilla/websocket):
102107
- Mature and widely used
103108
- [Prepared writes](https://pkg.go.dev/github.com/gorilla/websocket#PreparedMessage)
104109
- Configurable [buffer sizes](https://pkg.go.dev/github.com/gorilla/websocket#hdr-Buffers)
105-
- No extra goroutine per connection to support cancellation with context.Context. This costs nhooyr.io/websocket 2 KB of memory per connection.
110+
- No extra goroutine per connection to support cancellation with context.Context. This costs github.com/coder/websocket 2 KB of memory per connection.
106111
- Will be removed soon with [context.AfterFunc](https://github.com/golang/go/issues/57928). See [#411](https://github.com/nhooyr/websocket/issues/411)
107112

108-
Advantages of nhooyr.io/websocket:
113+
Advantages of github.com/coder/websocket:
109114

110115
- Minimal and idiomatic API
111-
- Compare godoc of [nhooyr.io/websocket](https://pkg.go.dev/nhooyr.io/websocket) with [gorilla/websocket](https://pkg.go.dev/github.com/gorilla/websocket) side by side.
112-
- [net.Conn](https://pkg.go.dev/nhooyr.io/websocket#NetConn) wrapper
116+
- Compare godoc of [github.com/coder/websocket](https://pkg.go.dev/github.com/coder/websocket) with [gorilla/websocket](https://pkg.go.dev/github.com/gorilla/websocket) side by side.
117+
- [net.Conn](https://pkg.go.dev/github.com/coder/websocket#NetConn) wrapper
113118
- Zero alloc reads and writes ([gorilla/websocket#535](https://github.com/gorilla/websocket/issues/535))
114119
- Full [context.Context](https://blog.golang.org/context) support
115120
- Dial uses [net/http.Client](https://golang.org/pkg/net/http/#Client)
116121
- Will enable easy HTTP/2 support in the future
117122
- Gorilla writes directly to a net.Conn and so duplicates features of net/http.Client.
118123
- Concurrent writes
119124
- Close handshake ([gorilla/websocket#448](https://github.com/gorilla/websocket/issues/448))
120-
- Idiomatic [ping pong](https://pkg.go.dev/nhooyr.io/websocket#Conn.Ping) API
125+
- Idiomatic [ping pong](https://pkg.go.dev/github.com/coder/websocket#Conn.Ping) API
121126
- Gorilla requires registering a pong callback before sending a Ping
122127
- Can target Wasm ([gorilla/websocket#432](https://github.com/gorilla/websocket/issues/432))
123-
- Transparent message buffer reuse with [wsjson](https://pkg.go.dev/nhooyr.io/websocket/wsjson) subpackage
128+
- Transparent message buffer reuse with [wsjson](https://pkg.go.dev/github.com/coder/websocket/wsjson) subpackage
124129
- [1.75x](https://github.com/nhooyr/websocket/releases/tag/v1.7.4) faster WebSocket masking implementation in pure Go
125130
- Gorilla's implementation is slower and uses [unsafe](https://golang.org/pkg/unsafe/).
126131
Soon we'll have assembly and be 3x faster [#326](https://github.com/nhooyr/websocket/pull/326)
127132
- Full [permessage-deflate](https://tools.ietf.org/html/rfc7692) compression extension support
128133
- Gorilla only supports no context takeover mode
129-
- [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))
134+
- [CloseRead](https://pkg.go.dev/github.com/coder/websocket#Conn.CloseRead) helper for write only connections ([gorilla/websocket#492](https://github.com/gorilla/websocket/issues/492))
130135

131136
#### golang.org/x/net/websocket
132137

133138
[golang.org/x/net/websocket](https://pkg.go.dev/golang.org/x/net/websocket) is deprecated.
134139
See [golang/go/issues/18152](https://github.com/golang/go/issues/18152).
135140

136-
The [net.Conn](https://pkg.go.dev/nhooyr.io/websocket#NetConn) can help in transitioning
137-
to nhooyr.io/websocket.
141+
The [net.Conn](https://pkg.go.dev/github.com/coder/websocket#NetConn) can help in transitioning
142+
to github.com/coder/websocket.
138143

139144
#### gobwas/ws
140145

@@ -143,7 +148,7 @@ in an event driven style for performance. See the author's [blog post](https://m
143148

144149
However it is quite bloated. See https://pkg.go.dev/github.com/gobwas/ws
145150

146-
When writing idiomatic Go, nhooyr.io/websocket will be faster and easier to use.
151+
When writing idiomatic Go, github.com/coder/websocket will be faster and easier to use.
147152

148153
#### lesismal/nbio
149154

@@ -152,4 +157,4 @@ event driven for performance reasons.
152157

153158
However it is quite bloated. See https://pkg.go.dev/github.com/lesismal/nbio
154159

155-
When writing idiomatic Go, nhooyr.io/websocket will be faster and easier to use.
160+
When writing idiomatic Go, github.com/coder/websocket will be faster and easier to use.

Diff for: accept.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"path/filepath"
1818
"strings"
1919

20-
"nhooyr.io/websocket/internal/errd"
20+
"github.com/coder/websocket/internal/errd"
2121
)
2222

2323
// AcceptOptions represents Accept's options.

Diff for: accept_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"sync"
1414
"testing"
1515

16-
"nhooyr.io/websocket/internal/test/assert"
17-
"nhooyr.io/websocket/internal/test/xrand"
16+
"github.com/coder/websocket/internal/test/assert"
17+
"github.com/coder/websocket/internal/test/xrand"
1818
)
1919

2020
func TestAccept(t *testing.T) {

Diff for: autobahn_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import (
1717
"testing"
1818
"time"
1919

20-
"nhooyr.io/websocket"
21-
"nhooyr.io/websocket/internal/errd"
22-
"nhooyr.io/websocket/internal/test/assert"
23-
"nhooyr.io/websocket/internal/test/wstest"
24-
"nhooyr.io/websocket/internal/util"
20+
"github.com/coder/websocket"
21+
"github.com/coder/websocket/internal/errd"
22+
"github.com/coder/websocket/internal/test/assert"
23+
"github.com/coder/websocket/internal/test/wstest"
24+
"github.com/coder/websocket/internal/util"
2525
)
2626

2727
var excludedAutobahnCases = []string{

Diff for: close.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"net"
1212
"time"
1313

14-
"nhooyr.io/websocket/internal/errd"
14+
"github.com/coder/websocket/internal/errd"
1515
)
1616

1717
// StatusCode represents a WebSocket status code.

Diff for: close_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010
"testing"
1111

12-
"nhooyr.io/websocket/internal/test/assert"
12+
"github.com/coder/websocket/internal/test/assert"
1313
)
1414

1515
func TestCloseError(t *testing.T) {

Diff for: compress_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"strings"
1111
"testing"
1212

13-
"nhooyr.io/websocket/internal/test/assert"
14-
"nhooyr.io/websocket/internal/test/xrand"
13+
"github.com/coder/websocket/internal/test/assert"
14+
"github.com/coder/websocket/internal/test/xrand"
1515
)
1616

1717
func Test_slidingWindow(t *testing.T) {

Diff for: conn_test.go

+20-8
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import (
1616
"testing"
1717
"time"
1818

19-
"nhooyr.io/websocket"
20-
"nhooyr.io/websocket/internal/errd"
21-
"nhooyr.io/websocket/internal/test/assert"
22-
"nhooyr.io/websocket/internal/test/wstest"
23-
"nhooyr.io/websocket/internal/test/xrand"
24-
"nhooyr.io/websocket/internal/xsync"
25-
"nhooyr.io/websocket/wsjson"
19+
"github.com/coder/websocket"
20+
"github.com/coder/websocket/internal/errd"
21+
"github.com/coder/websocket/internal/test/assert"
22+
"github.com/coder/websocket/internal/test/wstest"
23+
"github.com/coder/websocket/internal/test/xrand"
24+
"github.com/coder/websocket/internal/xsync"
25+
"github.com/coder/websocket/wsjson"
2626
)
2727

2828
func TestConn(t *testing.T) {
@@ -364,14 +364,26 @@ func TestWasm(t *testing.T) {
364364
defer cancel()
365365

366366
cmd := exec.CommandContext(ctx, "go", "test", "-exec=wasmbrowsertest", ".", "-v")
367-
cmd.Env = append(os.Environ(), "GOOS=js", "GOARCH=wasm", fmt.Sprintf("WS_ECHO_SERVER_URL=%v", s.URL))
367+
cmd.Env = append(cleanEnv(os.Environ()), "GOOS=js", "GOARCH=wasm", fmt.Sprintf("WS_ECHO_SERVER_URL=%v", s.URL))
368368

369369
b, err := cmd.CombinedOutput()
370370
if err != nil {
371371
t.Fatalf("wasm test binary failed: %v:\n%s", err, b)
372372
}
373373
}
374374

375+
func cleanEnv(env []string) (out []string) {
376+
for _, e := range env {
377+
// Filter out GITHUB envs and anything with token in it,
378+
// especially GITHUB_TOKEN in CI as it breaks TestWasm.
379+
if strings.HasPrefix(e, "GITHUB") || strings.Contains(e, "TOKEN") {
380+
continue
381+
}
382+
out = append(out, e)
383+
}
384+
return out
385+
}
386+
375387
func assertCloseStatus(exp websocket.StatusCode, err error) error {
376388
if websocket.CloseStatus(err) == -1 {
377389
return fmt.Errorf("expected websocket.CloseError: %T %v", err, err)

Diff for: dial.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"sync"
1818
"time"
1919

20-
"nhooyr.io/websocket/internal/errd"
20+
"github.com/coder/websocket/internal/errd"
2121
)
2222

2323
// DialOptions represents Dial's options.

Diff for: dial_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import (
1515
"testing"
1616
"time"
1717

18-
"nhooyr.io/websocket"
19-
"nhooyr.io/websocket/internal/test/assert"
20-
"nhooyr.io/websocket/internal/util"
21-
"nhooyr.io/websocket/internal/xsync"
18+
"github.com/coder/websocket"
19+
"github.com/coder/websocket/internal/test/assert"
20+
"github.com/coder/websocket/internal/util"
21+
"github.com/coder/websocket/internal/xsync"
2222
)
2323

2424
func TestBadDials(t *testing.T) {

Diff for: doc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//
1616
// The wsjson subpackage contain helpers for JSON and protobuf messages.
1717
//
18-
// More documentation at https://nhooyr.io/websocket.
18+
// More documentation at https://github.com/coder/websocket.
1919
//
2020
// # Wasm
2121
//
@@ -31,4 +31,4 @@
3131
// - Conn.CloseNow is Close(StatusGoingAway, "")
3232
// - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
3333
// - *http.Response from Dial is &http.Response{} with a 101 status code on success
34-
package websocket // import "nhooyr.io/websocket"
34+
package websocket // import "github.com/coder/websocket"

Diff for: example_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"net/http"
77
"time"
88

9-
"nhooyr.io/websocket"
10-
"nhooyr.io/websocket/wsjson"
9+
"github.com/coder/websocket"
10+
"github.com/coder/websocket/wsjson"
1111
)
1212

1313
func ExampleAccept() {

Diff for: export_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package websocket
66
import (
77
"net"
88

9-
"nhooyr.io/websocket/internal/util"
9+
"github.com/coder/websocket/internal/util"
1010
)
1111

1212
func (c *Conn) RecordBytesWritten() *int {

Diff for: frame.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"io"
1010
"math"
1111

12-
"nhooyr.io/websocket/internal/errd"
12+
"github.com/coder/websocket/internal/errd"
1313
)
1414

1515
// opcode represents a WebSocket opcode.

Diff for: frame_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"testing"
1414
"time"
1515

16-
"nhooyr.io/websocket/internal/test/assert"
16+
"github.com/coder/websocket/internal/test/assert"
1717
)
1818

1919
func TestHeader(t *testing.T) {

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module nhooyr.io/websocket
1+
module github.com/coder/websocket
22

33
go 1.19

Diff for: internal/examples/chat/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Chat Example
22

3-
This directory contains a full stack example of a simple chat webapp using nhooyr.io/websocket.
3+
This directory contains a full stack example of a simple chat webapp using github.com/coder/websocket.
44

55
```bash
66
$ cd examples/chat

Diff for: internal/examples/chat/chat.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"golang.org/x/time/rate"
1414

15-
"nhooyr.io/websocket"
15+
"github.com/coder/websocket"
1616
)
1717

1818
// chatServer enables broadcasting to a set of subscribers.

Diff for: internal/examples/chat/chat_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
"golang.org/x/time/rate"
1616

17-
"nhooyr.io/websocket"
17+
"github.com/coder/websocket"
1818
)
1919

2020
func Test_chatServer(t *testing.T) {

Diff for: internal/examples/chat/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en-CA">
33
<head>
44
<meta charset="UTF-8" />
5-
<title>nhooyr.io/websocket - Chat Example</title>
5+
<title>github.com/coder/websocket - Chat Example</title>
66
<meta name="viewport" content="width=device-width" />
77

88
<link href="https://unpkg.com/sanitize.css" rel="stylesheet" />

0 commit comments

Comments
 (0)