good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit 6b2e258f authored by Anmol Sethi's avatar Anmol Sethi
Browse files

Fixes for release

Closes #69
parent 751a0ed7
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......@@ -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
......@@ -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
......
......@@ -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, "")
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment