@@ -7,8 +7,6 @@ websocket is a minimal and idiomatic WebSocket library for Go.
7
7
8
8
This library is not final and the API is subject to change.
9
9
10
- If you have any feedback, please feel free to open an issue.
11
-
12
10
## Install
13
11
14
12
``` bash
17
15
18
16
## Features
19
17
20
- - Minimal yet pragmatic API
18
+ - Minimal and idiomatic API
19
+ - Tiny codebase at 1400 lines which reduces the surface area for bugs
21
20
- 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 )
24
22
- Zero dependencies outside of the stdlib for the core library
25
23
- JSON and ProtoBuf helpers in the wsjson and wspb subpackages
24
+ - High performance
25
+ - Concurrent writes
26
26
27
27
## Roadmap
28
28
@@ -78,9 +78,10 @@ if err != nil {
78
78
c.Close (websocket.StatusNormalClosure , " " )
79
79
```
80
80
81
- ## Design considerations
81
+ ## Design justifications
82
82
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
84
85
- Context based cancellation is more ergonomic and robust than setting deadlines
85
86
- No ping support because TCP keep alives work fine for HTTP/1.1 and they do not make
86
87
sense with HTTP/2 (see [ #1 ] ( https://github.com/nhooyr/websocket/issues/1 ) )
@@ -90,12 +91,11 @@ c.Close(websocket.StatusNormalClosure, "")
90
91
91
92
## Comparison
92
93
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.
99
99
100
100
### gorilla/websocket
101
101
@@ -108,14 +108,24 @@ and there are some rough edges. Just compare the godoc of
108
108
[ gorilla/websocket] ( https://godoc.org/github.com/gorilla/websocket ) .
109
109
110
110
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.
112
114
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
114
120
also uses net/http's Client and ResponseWriter directly for WebSocket handshakes.
115
121
gorilla/websocket writes its handshakes to the underlying net.Conn which means
116
122
it has to reinvent hooks for TLS and proxying and prevents support of HTTP/2.
117
123
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 ) ).
119
129
120
130
### x/net/websocket
121
131
@@ -130,7 +140,7 @@ See https://github.com/golang/go/issues/18152
130
140
https://github.com/gobwas/ws
131
141
132
142
This library has an extremely flexible API but that comes at the cost of usability
133
- and clarity.
143
+ and clarity.
134
144
135
145
This library is fantastic in terms of performance. The author put in significant
136
146
effort to ensure its speed and I have applied as many of its optimizations as
0 commit comments