status-go/vendor/nhooyr.io/websocket
RichΛrd 0babdad17b
chore: upgrade go-waku to v0.5 (#3213)
* chore: upgrade go-waku to v0.5
* chore: add println and logs to check what's being stored in the enr, and preemptively delete the multiaddr field (#3219)
* feat: add wakuv2 test (#3218)
2023-02-22 17:58:17 -04:00
..
internal chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
.gitignore chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
LICENSE.txt chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
README.md chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
accept.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
accept_js.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
close.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
close_notjs.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
compress.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
compress_notjs.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
conn.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
conn_notjs.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
dial.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
doc.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
frame.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
netconn.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
read.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
stringer.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
write.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00
ws_js.go chore: upgrade go-waku to v0.5 (#3213) 2023-02-22 17:58:17 -04:00

README.md

websocket

godoc coverage

websocket is a minimal and idiomatic WebSocket library for Go.

Install

go get nhooyr.io/websocket

Highlights

Roadmap

  • HTTP/2 #4

Examples

For a production quality example that demonstrates the complete API, see the echo example.

For a full stack example, see the chat example.

Server

http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
	c, err := websocket.Accept(w, r, nil)
	if err != nil {
		// ...
	}
	defer c.Close(websocket.StatusInternalError, "the sky is falling")

	ctx, cancel := context.WithTimeout(r.Context(), time.Second*10)
	defer cancel()

	var v interface{}
	err = wsjson.Read(ctx, c, &v)
	if err != nil {
		// ...
	}

	log.Printf("received: %v", v)

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

Client

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

c, _, err := websocket.Dial(ctx, "ws://localhost:8080", nil)
if err != nil {
	// ...
}
defer c.Close(websocket.StatusInternalError, "the sky is falling")

err = wsjson.Write(ctx, c, "hi")
if err != nil {
	// ...
}

c.Close(websocket.StatusNormalClosure, "")

Comparison

gorilla/websocket

Advantages of gorilla/websocket:

Advantages of nhooyr.io/websocket:

golang.org/x/net/websocket

golang.org/x/net/websocket is deprecated. See golang/go/issues/18152.

The net.Conn can help in transitioning to nhooyr.io/websocket.

gobwas/ws

gobwas/ws has an extremely flexible API that allows it to be used in an event driven style for performance. See the author's blog post.

However when writing idiomatic Go, nhooyr.io/websocket will be faster and easier to use.