From 6b2e258fee847c8ddfb95eeb4263758fd6ea2805 Mon Sep 17 00:00:00 2001 From: Anmol Sethi <hi@nhooyr.io> Date: Sat, 27 Apr 2019 11:25:29 -0400 Subject: [PATCH] Fixes for release Closes #69 --- README.md | 21 ++++++++++----------- doc.go | 8 +++++--- example_echo_test.go | 4 ++-- example_test.go | 9 ++++----- statuscode.go | 1 + 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 53507a6..5e7c150 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ If you have any feedback, please feel free to open an issue. ## Install ```bash -go get nhooyr.io/websocket +go get nhooyr.io/websocket@0.2.0 ``` ## Features @@ -85,9 +85,8 @@ c.Close(websocket.StatusNormalClosure, "") - Minimal API is easier to maintain and learn - Context based cancellation is more ergonomic and robust than setting deadlines - No ping support because TCP keep alives work fine for HTTP/1.1 and they do not make - sense with HTTP/2 (see #1) -- net.Conn is never exposed as WebSocket's over HTTP/2 will not have a net.Conn. -- Structures are nicer than functional options, see [google/go-cloud#908](https://github.com/google/go-cloud/issues/908#issuecomment-445034143) + sense with HTTP/2 (see [#1](https://github.com/nhooyr/websocket/issues/1)) +- net.Conn is never exposed as WebSocket over HTTP/2 will not have a net.Conn. - Using net/http's Client for dialing means we do not have to reinvent dialing hooks and configurations like other WebSocket libraries @@ -105,7 +104,7 @@ in production. https://github.com/gorilla/websocket This package is the community standard but it is 6 years old and over time -has accumulated cruft. There are many ways to do the same thing, usage is not clear +has accumulated cruft. Using is not clear as there are many ways to do things and there are some rough edges. Just compare the godoc of [nhooyr/websocket](https://godoc.org/github.com/nhooyr/websocket) side by side with [gorilla/websocket](https://godoc.org/github.com/gorilla/websocket). @@ -115,11 +114,10 @@ which makes it easy to use correctly. Furthermore, nhooyr/websocket has support for newer Go idioms such as context.Context and also uses net/http's Client and ResponseWriter directly for WebSocket handshakes. -gorilla/websocket writes its handshakes directly to a net.Conn which means +gorilla/websocket writes its handshakes to the underlying net.Conn which means it has to reinvent hooks for TLS and proxying and prevents support of HTTP/2. -Another advantage of nhooyr/websocket is that it supports multiple concurrent writers out -of the box. +Another advantage of nhooyr/websocket is that it supports concurrent writers out of the box. ### x/net/websocket @@ -138,8 +136,9 @@ and clarity. This library is fantastic in terms of performance. The author put in significant effort to ensure its speed and I have applied as many of its optimizations as -I could into nhooyr/websocket. Definitely check out his fantastic [blog post](https://medium.freecodecamp.org/million-websockets-and-go-cc58418460bb) about performant WebSocket servers. +I could into nhooyr/websocket. Definitely check out his fantastic [blog post](https://medium.freecodecamp.org/million-websockets-and-go-cc58418460bb) +about performant WebSocket servers. If you want a library that gives you absolute control over everything, this is the library, -but for most users, the API provided by nhooyr/websocket will fit better as it is just as -performant but much easier to use correctly and idiomatic. +but for most users, the API provided by nhooyr/websocket will fit better as it is nearly just +as performant but much easier to use correctly and idiomatic. diff --git a/doc.go b/doc.go index 0b873b4..6ee4166 100644 --- a/doc.go +++ b/doc.go @@ -2,9 +2,6 @@ // // See https://tools.ietf.org/html/rfc6455 // -// Please see https://nhooyr.io/websocket for overview docs and a -// comparison with existing implementations. -// // Conn, Dial, and Accept are the main entrypoints into this package. Use Dial to dial // a WebSocket server, Accept to accept a WebSocket client dial and then Conn to interact // with the resulting WebSocket connections. @@ -12,4 +9,9 @@ // The examples are the best way to understand how to correctly use the library. // // The wsjson and wspb subpackages contain helpers for JSON and ProtoBuf messages. +// +// Please see https://nhooyr.io/websocket for more overview docs and a +// comparison with existing implementations. +// +// Please be sure to use the https://golang.org/x/xerrors package when inspecting returned errors. package websocket diff --git a/example_echo_test.go b/example_echo_test.go index a90257b..ab0e8e7 100644 --- a/example_echo_test.go +++ b/example_echo_test.go @@ -16,8 +16,8 @@ import ( "nhooyr.io/websocket/wsjson" ) -// This example starts a WebSocket echo server and -// then dials the server and sends 5 different messages +// This example starts a WebSocket echo server, +// dials the server and then sends 5 different messages // and prints out the server's responses. func Example_echo() { // First we listen on port 0, that means the OS will diff --git a/example_test.go b/example_test.go index 7a0528c..57f0aa5 100644 --- a/example_test.go +++ b/example_test.go @@ -36,7 +36,8 @@ func ExampleAccept() { c.Close(websocket.StatusNormalClosure, "") }) - http.ListenAndServe("localhost:8080", fn) + err := http.ListenAndServe("localhost:8080", fn) + log.Fatal(err) } // This example dials a server, writes a single JSON message and then @@ -47,15 +48,13 @@ func ExampleDial() { c, _, err := websocket.Dial(ctx, "ws://localhost:8080", websocket.DialOptions{}) if err != nil { - log.Println(err) - return + log.Fatal(err) } defer c.Close(websocket.StatusInternalError, "the sky is falling") err = wsjson.Write(ctx, c, "hi") if err != nil { - log.Println(err) - return + log.Fatal(err) } c.Close(websocket.StatusNormalClosure, "") diff --git a/statuscode.go b/statuscode.go index 69b015c..d422374 100644 --- a/statuscode.go +++ b/statuscode.go @@ -42,6 +42,7 @@ const ( // CloseError represents a WebSocket close frame. // It is returned by Conn's methods when the Connection is closed with a WebSocket close frame. +// You will need to use https://golang.org/x/xerrors to check for this error. type CloseError struct { Code StatusCode Reason string -- GitLab