Skip to content

Commit

Permalink
更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
guonaihong committed May 21, 2024
1 parent 96abebd commit c2492ac
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 16 deletions.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ quickws是一个高性能的websocket库
* [配置socks5代理](#配置socks5代理)
* [配置proxy代理](#配置proxy代理)
* [配置客户端最大读取message](#配置客户端最大读message)
* [配置客户端压缩和解压消息](#配置客户端压缩和解压消息)
* [配置客户端上下文接管](#配置客户端上下文接管)
* [服务配置参数](#服务端配置)
* [配置服务自动回复ping消息](#配置服务自动回复ping消息)
* [配置服务端最大读取message](#配置服务端最大读message)
* [配置服务端解压消息](#配置服务端解压消息)
* [配置服务端压缩和解压消息](#配置服务端压缩和解压消息)
* [配置服务端上下文接管](#配置服务端上下文接管)
## 注意⚠️
quickws默认返回read buffer的浅引用,如果生命周期超过OnMessage的,需要clone一份再使用

Expand Down Expand Up @@ -207,6 +212,7 @@ func main() {
quickws.Dial("ws://127.0.0.1:12345/test", quickws.WithClientReplyPing())
}
```
[返回](#内容)
#### 配置socks5代理
```go
import(
Expand Down Expand Up @@ -239,8 +245,24 @@ func main() {
[返回](#内容)
#### 配置客户端最大读message
```go
func main() {
// 限制客户端最大服务返回返回的最大包是1024,如果超过这个大小报错
quickws.Dial("ws://127.0.0.1:12345/test", quickws.WithClientReadMaxMessage(1024))
}
```
[返回](#内容)
#### 配置客户端压缩和解压消息
```go
func main() {
quickws.Dial("ws://127.0.0.1:12345/test", quickws.WithClientDecompressAndCompress())
}
```
[返回](#内容)
#### 配置客户端上下文接管
```go
func main() {
quickws.Dial("ws://127.0.0.1:12345/test", quickws.WithClientContextTakeover())
}
```
[返回](#内容)
### 服务端配置参数
Expand Down Expand Up @@ -268,6 +290,41 @@ func main() {
}
```
[返回](#内容)
#### 配置服务端解压消息
```go
func main() {
// 配置服务端读取客户端最大的包是1024大小, 超过该值报错
c, err := quickws.Upgrade(w, r, quickws.WithServerDecompression())
if err != nil {
fmt.Println("Upgrade fail:", err)
return
}
}
```
[返回](#内容)
#### 配置服务端压缩和解压消息
```go
func main() {
c, err := quickws.Upgrade(w, r, quickws.WithServerDecompressAndCompress())
if err != nil {
fmt.Println("Upgrade fail:", err)
return
}
}
```
[返回](#内容)
#### 配置服务端上下文接管
```go
func main() {
// 配置服务端读取客户端最大的包是1024大小, 超过该值报错
c, err := quickws.Upgrade(w, r, quickws.WithServerContextTakeover)
if err != nil {
fmt.Println("Upgrade fail:", err)
return
}
}
```
[返回](#内容)
## 常见问题
### 1.为什么quickws不标榜zero upgrade?
第一:quickws 是基于 std 的方案实现的 websocket 协议。
Expand Down
16 changes: 0 additions & 16 deletions client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,6 @@ func WithClientCompression() ClientOption {
}
}

// 5.1配置客户端压缩和解压缩
func WithClientDecompressAndCompress() ClientOption {
return func(o *DialOption) {
o.Compression = true
o.Decompression = true
}
}

// 5.2配置服务端压缩和解压缩
func WithServerDecompressAndCompress() ServerOption {
return func(o *ConnOption) {
o.Compression = true
o.Decompression = true
}
}

// 6.获取http header
func WithClientBindHTTPHeader(h *http.Header) ClientOption {
return func(o *DialOption) {
Expand Down
16 changes: 16 additions & 0 deletions common_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,19 @@ func WithServerReadMaxMessage(size int64) ServerOption {
o.readMaxMessage = size
}
}

// 22.1配置客户端压缩和解压缩
func WithClientDecompressAndCompress() ClientOption {
return func(o *DialOption) {
o.Compression = true
o.Decompression = true
}
}

// 22.2配置服务端压缩和解压缩
func WithServerDecompressAndCompress() ServerOption {
return func(o *ConnOption) {
o.Compression = true
o.Decompression = true
}
}

0 comments on commit c2492ac

Please sign in to comment.