Skip to content

Update import path to github.com/coder/websocket #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ jobs:
- uses: actions/checkout@v4
- run: go version
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- run: ./ci/lint.sh

test:
Expand Down
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# websocket

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

websocket is a minimal and idiomatic WebSocket library for Go.

## Install

```sh
go get nhooyr.io/websocket
go get github.com/coder/websocket
```

## Highlights

- Minimal and idiomatic API
- First class [context.Context](https://blog.golang.org/context) support
- Fully passes the WebSocket [autobahn-testsuite](https://github.com/crossbario/autobahn-testsuite)
- [Zero dependencies](https://pkg.go.dev/nhooyr.io/websocket?tab=imports)
- JSON helpers in the [wsjson](https://pkg.go.dev/nhooyr.io/websocket/wsjson) subpackage
- [Zero dependencies](https://pkg.go.dev/github.com/coder/websocket?tab=imports)
- JSON helpers in the [wsjson](https://pkg.go.dev/github.com/coder/websocket/wsjson) subpackage
- Zero alloc reads and writes
- Concurrent writes
- [Close handshake](https://pkg.go.dev/nhooyr.io/websocket#Conn.Close)
- [net.Conn](https://pkg.go.dev/nhooyr.io/websocket#NetConn) wrapper
- [Ping pong](https://pkg.go.dev/nhooyr.io/websocket#Conn.Ping) API
- [Close handshake](https://pkg.go.dev/github.com/coder/websocket#Conn.Close)
- [net.Conn](https://pkg.go.dev/github.com/coder/websocket#NetConn) wrapper
- [Ping pong](https://pkg.go.dev/github.com/coder/websocket#Conn.Ping) API
- [RFC 7692](https://tools.ietf.org/html/rfc7692) permessage-deflate compression
- [CloseRead](https://pkg.go.dev/nhooyr.io/websocket#Conn.CloseRead) helper for write only connections
- Compile to [Wasm](https://pkg.go.dev/nhooyr.io/websocket#hdr-Wasm)
- [CloseRead](https://pkg.go.dev/github.com/coder/websocket#Conn.CloseRead) helper for write only connections
- Compile to [Wasm](https://pkg.go.dev/github.com/coder/websocket#hdr-Wasm)

## Roadmap

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

Advantages of nhooyr.io/websocket:
Advantages of github.com/coder/websocket:

- Minimal and idiomatic API
- 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.
- [net.Conn](https://pkg.go.dev/nhooyr.io/websocket#NetConn) wrapper
- 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.
- [net.Conn](https://pkg.go.dev/github.com/coder/websocket#NetConn) wrapper
- Zero alloc reads and writes ([gorilla/websocket#535](https://github.com/gorilla/websocket/issues/535))
- Full [context.Context](https://blog.golang.org/context) support
- Dial uses [net/http.Client](https://golang.org/pkg/net/http/#Client)
- Will enable easy HTTP/2 support in the future
- Gorilla writes directly to a net.Conn and so duplicates features of net/http.Client.
- Concurrent writes
- Close handshake ([gorilla/websocket#448](https://github.com/gorilla/websocket/issues/448))
- Idiomatic [ping pong](https://pkg.go.dev/nhooyr.io/websocket#Conn.Ping) API
- Idiomatic [ping pong](https://pkg.go.dev/github.com/coder/websocket#Conn.Ping) API
- Gorilla requires registering a pong callback before sending a Ping
- Can target Wasm ([gorilla/websocket#432](https://github.com/gorilla/websocket/issues/432))
- Transparent message buffer reuse with [wsjson](https://pkg.go.dev/nhooyr.io/websocket/wsjson) subpackage
- Transparent message buffer reuse with [wsjson](https://pkg.go.dev/github.com/coder/websocket/wsjson) subpackage
- [1.75x](https://github.com/nhooyr/websocket/releases/tag/v1.7.4) faster WebSocket masking implementation in pure Go
- Gorilla's implementation is slower and uses [unsafe](https://golang.org/pkg/unsafe/).
Soon we'll have assembly and be 3x faster [#326](https://github.com/nhooyr/websocket/pull/326)
- Full [permessage-deflate](https://tools.ietf.org/html/rfc7692) compression extension support
- Gorilla only supports no context takeover mode
- [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))
- [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))

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

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

The [net.Conn](https://pkg.go.dev/nhooyr.io/websocket#NetConn) can help in transitioning
to nhooyr.io/websocket.
The [net.Conn](https://pkg.go.dev/github.com/coder/websocket#NetConn) can help in transitioning
to github.com/coder/websocket.

#### gobwas/ws

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

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

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

#### lesismal/nbio

Expand All @@ -152,4 +152,4 @@ event driven for performance reasons.

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

When writing idiomatic Go, nhooyr.io/websocket will be faster and easier to use.
When writing idiomatic Go, github.com/coder/websocket will be faster and easier to use.
2 changes: 1 addition & 1 deletion accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"path/filepath"
"strings"

"nhooyr.io/websocket/internal/errd"
"github.com/coder/websocket/internal/errd"
)

// AcceptOptions represents Accept's options.
Expand Down
4 changes: 2 additions & 2 deletions accept_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"sync"
"testing"

"nhooyr.io/websocket/internal/test/assert"
"nhooyr.io/websocket/internal/test/xrand"
"github.com/coder/websocket/internal/test/assert"
"github.com/coder/websocket/internal/test/xrand"
)

func TestAccept(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions autobahn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"testing"
"time"

"nhooyr.io/websocket"
"nhooyr.io/websocket/internal/errd"
"nhooyr.io/websocket/internal/test/assert"
"nhooyr.io/websocket/internal/test/wstest"
"nhooyr.io/websocket/internal/util"
"github.com/coder/websocket"
"github.com/coder/websocket/internal/errd"
"github.com/coder/websocket/internal/test/assert"
"github.com/coder/websocket/internal/test/wstest"
"github.com/coder/websocket/internal/util"
)

var excludedAutobahnCases = []string{
Expand Down
2 changes: 1 addition & 1 deletion close.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"net"
"time"

"nhooyr.io/websocket/internal/errd"
"github.com/coder/websocket/internal/errd"
)

// StatusCode represents a WebSocket status code.
Expand Down
2 changes: 1 addition & 1 deletion close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"testing"

"nhooyr.io/websocket/internal/test/assert"
"github.com/coder/websocket/internal/test/assert"
)

func TestCloseError(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions compress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"strings"
"testing"

"nhooyr.io/websocket/internal/test/assert"
"nhooyr.io/websocket/internal/test/xrand"
"github.com/coder/websocket/internal/test/assert"
"github.com/coder/websocket/internal/test/xrand"
)

func Test_slidingWindow(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (
"testing"
"time"

"nhooyr.io/websocket"
"nhooyr.io/websocket/internal/errd"
"nhooyr.io/websocket/internal/test/assert"
"nhooyr.io/websocket/internal/test/wstest"
"nhooyr.io/websocket/internal/test/xrand"
"nhooyr.io/websocket/internal/xsync"
"nhooyr.io/websocket/wsjson"
"github.com/coder/websocket"
"github.com/coder/websocket/internal/errd"
"github.com/coder/websocket/internal/test/assert"
"github.com/coder/websocket/internal/test/wstest"
"github.com/coder/websocket/internal/test/xrand"
"github.com/coder/websocket/internal/xsync"
"github.com/coder/websocket/wsjson"
)

func TestConn(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"sync"
"time"

"nhooyr.io/websocket/internal/errd"
"github.com/coder/websocket/internal/errd"
)

// DialOptions represents Dial's options.
Expand Down
8 changes: 4 additions & 4 deletions dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
"testing"
"time"

"nhooyr.io/websocket"
"nhooyr.io/websocket/internal/test/assert"
"nhooyr.io/websocket/internal/util"
"nhooyr.io/websocket/internal/xsync"
"github.com/coder/websocket"
"github.com/coder/websocket/internal/test/assert"
"github.com/coder/websocket/internal/util"
"github.com/coder/websocket/internal/xsync"
)

func TestBadDials(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//
// The wsjson subpackage contain helpers for JSON and protobuf messages.
//
// More documentation at https://nhooyr.io/websocket.
// More documentation at https://github.com/coder/websocket.
//
// # Wasm
//
Expand All @@ -31,4 +31,4 @@
// - Conn.CloseNow is Close(StatusGoingAway, "")
// - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
// - *http.Response from Dial is &http.Response{} with a 101 status code on success
package websocket // import "nhooyr.io/websocket"
package websocket // import "github.com/coder/websocket"
4 changes: 2 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"net/http"
"time"

"nhooyr.io/websocket"
"nhooyr.io/websocket/wsjson"
"github.com/coder/websocket"
"github.com/coder/websocket/wsjson"
)

func ExampleAccept() {
Expand Down
2 changes: 1 addition & 1 deletion export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package websocket
import (
"net"

"nhooyr.io/websocket/internal/util"
"github.com/coder/websocket/internal/util"
)

func (c *Conn) RecordBytesWritten() *int {
Expand Down
2 changes: 1 addition & 1 deletion frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"io"
"math"

"nhooyr.io/websocket/internal/errd"
"github.com/coder/websocket/internal/errd"
)

// opcode represents a WebSocket opcode.
Expand Down
2 changes: 1 addition & 1 deletion frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"testing"
"time"

"nhooyr.io/websocket/internal/test/assert"
"github.com/coder/websocket/internal/test/assert"
)

func TestHeader(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module nhooyr.io/websocket
module github.com/coder/websocket

go 1.19
2 changes: 1 addition & 1 deletion internal/examples/chat/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Chat Example

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

```bash
$ cd examples/chat
Expand Down
2 changes: 1 addition & 1 deletion internal/examples/chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"golang.org/x/time/rate"

"nhooyr.io/websocket"
"github.com/coder/websocket"
)

// chatServer enables broadcasting to a set of subscribers.
Expand Down
2 changes: 1 addition & 1 deletion internal/examples/chat/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"golang.org/x/time/rate"

"nhooyr.io/websocket"
"github.com/coder/websocket"
)

func Test_chatServer(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/examples/chat/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en-CA">
<head>
<meta charset="UTF-8" />
<title>nhooyr.io/websocket - Chat Example</title>
<title>github.com/coder/websocket - Chat Example</title>
<meta name="viewport" content="width=device-width" />

<link href="https://unpkg.com/sanitize.css" rel="stylesheet" />
Expand Down
2 changes: 1 addition & 1 deletion internal/examples/echo/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Echo Example

This directory contains a echo server example using nhooyr.io/websocket.
This directory contains a echo server example using github.com/coder/websocket.

```bash
$ cd examples/echo
Expand Down
2 changes: 1 addition & 1 deletion internal/examples/echo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"golang.org/x/time/rate"

"nhooyr.io/websocket"
"github.com/coder/websocket"
)

// echoServer is the WebSocket echo server implementation.
Expand Down
4 changes: 2 additions & 2 deletions internal/examples/echo/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"testing"
"time"

"nhooyr.io/websocket"
"nhooyr.io/websocket/wsjson"
"github.com/coder/websocket"
"github.com/coder/websocket/wsjson"
)

// Test_echoServer tests the echoServer by sending it 5 different messages
Expand Down
6 changes: 3 additions & 3 deletions internal/examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module nhooyr.io/websocket/examples
module github.com/coder/websocket/examples

go 1.19

replace nhooyr.io/websocket => ../..
replace github.com/coder/websocket => ../..

require (
github.com/coder/websocket v0.0.0-00010101000000-000000000000
golang.org/x/time v0.3.0
nhooyr.io/websocket v0.0.0-00010101000000-000000000000
)
6 changes: 3 additions & 3 deletions internal/test/wstest/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"io"
"time"

"nhooyr.io/websocket"
"nhooyr.io/websocket/internal/test/xrand"
"nhooyr.io/websocket/internal/xsync"
"github.com/coder/websocket"
"github.com/coder/websocket/internal/test/xrand"
"github.com/coder/websocket/internal/xsync"
)

// EchoLoop echos every msg received from c until an error
Expand Down
2 changes: 1 addition & 1 deletion internal/test/wstest/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"net/http"
"net/http/httptest"

"nhooyr.io/websocket"
"github.com/coder/websocket"
)

// Pipe is used to create an in memory connection
Expand Down
Loading
Loading