Skip to content

Commit 50a44cf

Browse files
committed
Improve README.md
Updates #75
1 parent b7e380e commit 50a44cf

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

README.md

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ websocket is a minimal and idiomatic WebSocket library for Go.
77

88
This library is not final and the API is subject to change.
99

10-
If you have any feedback, please feel free to open an issue.
11-
1210
## Install
1311

1412
```bash
@@ -17,12 +15,14 @@ go get nhooyr.io/[email protected]
1715

1816
## Features
1917

20-
- Minimal yet pragmatic API
18+
- Minimal and idiomatic API
19+
- Tiny codebase at 1400 lines which reduces the surface area for bugs
2120
- First class context.Context support
22-
- Thoroughly tested, fully passes the [autobahn-testsuite](https://github.com/crossbario/autobahn-testsuite)
23-
- Concurrent writes
21+
- Thorough tests, fully passes the [autobahn-testsuite](https://github.com/crossbario/autobahn-testsuite)
2422
- Zero dependencies outside of the stdlib for the core library
2523
- JSON and ProtoBuf helpers in the wsjson and wspb subpackages
24+
- High performance
25+
- Concurrent writes
2626

2727
## Roadmap
2828

@@ -78,9 +78,10 @@ if err != nil {
7878
c.Close(websocket.StatusNormalClosure, "")
7979
```
8080

81-
## Design considerations
81+
## Design justifications
8282

83-
- Minimal API is easier to maintain and learn
83+
- A minimal API is easier to maintain due to less docs, tests and bugs
84+
- A minimal API is also easier to use and learn
8485
- Context based cancellation is more ergonomic and robust than setting deadlines
8586
- No ping support because TCP keep alives work fine for HTTP/1.1 and they do not make
8687
sense with HTTP/2 (see [#1](https://github.com/nhooyr/websocket/issues/1))
@@ -90,12 +91,11 @@ c.Close(websocket.StatusNormalClosure, "")
9091

9192
## Comparison
9293

93-
While I believe nhooyr/websocket has a better API than existing libraries,
94-
both gorilla/websocket and gobwas/ws were extremely useful in implementing the
95-
WebSocket protocol correctly so *big thanks* to the authors of both. In particular,
96-
I made sure to go through the issue tracker of gorilla/websocket to make sure
97-
I implemented details correctly and understood how people were using the package
98-
in production.
94+
Before the comparison, I want to point out that both gorilla/websocket and gobwas/ws were
95+
extremely useful in implementing the WebSocket protocol correctly so *big thanks* to the
96+
authors of both. In particular, I made sure to go through the issue tracker of gorilla/websocket
97+
to ensure I implemented details correctly and understood how people were using WebSockets in
98+
production.
9999

100100
### gorilla/websocket
101101

@@ -108,14 +108,24 @@ and there are some rough edges. Just compare the godoc of
108108
[gorilla/websocket](https://godoc.org/github.com/gorilla/websocket).
109109

110110
The API for nhooyr/websocket has been designed such that there is only one way to do things
111-
which makes it easy to use correctly.
111+
which makes it easy to use correctly. Not only is the API simpler, the implementation is
112+
only 1400 lines whereas gorilla/websocket is at 3500 lines. That's more code to maintain,
113+
more code to test, more code to document and more surface area for bugs.
112114

113-
Furthermore, nhooyr/websocket has support for newer Go idioms such as context.Context and
115+
The future of gorilla/websocket is also uncertain. See [gorilla/websocket#370](https://github.com/gorilla/websocket/issues/370).
116+
117+
Pure conjecture but I would argue that the sprawling API has made it difficult to maintain.
118+
119+
Moreover, nhooyr/websocket has support for newer Go idioms such as context.Context and
114120
also uses net/http's Client and ResponseWriter directly for WebSocket handshakes.
115121
gorilla/websocket writes its handshakes to the underlying net.Conn which means
116122
it has to reinvent hooks for TLS and proxying and prevents support of HTTP/2.
117123

118-
Another advantage of nhooyr/websocket is that it supports concurrent writers out of the box.
124+
Some more advantages of nhooyr/websocket are that it supports concurrent writes and makes it
125+
very easy to close the connection with a status code and reason compared to gorilla/websocket.
126+
127+
In terms of performance, there is no significant difference between the two. Will update
128+
with benchmarks soon ([#75](https://github.com/nhooyr/websocket/issues/75)).
119129

120130
### x/net/websocket
121131

@@ -130,7 +140,7 @@ See https://github.com/golang/go/issues/18152
130140
https://github.com/gobwas/ws
131141

132142
This library has an extremely flexible API but that comes at the cost of usability
133-
and clarity.
143+
and clarity.
134144

135145
This library is fantastic in terms of performance. The author put in significant
136146
effort to ensure its speed and I have applied as many of its optimizations as

0 commit comments

Comments
 (0)