通过 `NewDialer` 选项设置拨号器, 推荐使用` socks5` 代理. 需要引入 `golang.org/x/net/proxy`, 代码示例如下:
```go
package main
import (
"crypto/tls"
"github.com/lxzan/gws"
"golang.org/x/net/proxy"
"log"
)
func main() {
socket, _, err := gws.NewClient(&Handler{}, &gws.ClientOption{
Addr: "wss://example.com/connect",
TlsConfig: &tls.Config{InsecureSkipVerify: true},
NewDialer: func() (gws.Dialer, error) {
return proxy.SOCKS5("tcp", "127.0.0.1:1080", nil, nil)
},
})
if err != nil {
log.Println(err.Error())
return
}
socket.ReadLoop()
}
type Handler struct{}
func (h Handler) OnOpen(socket *gws.Conn) {}
func (h Handler) OnClose(socket *gws.Conn, err error) {}
func (h Handler) OnPing(socket *gws.Conn, payload []byte) {}
func (h Handler) OnPong(socket *gws.Conn, payload []byte) {}
func (h Handler) OnMessage(socket *gws.Conn, message *gws.Message) {}
```
##### 开源不易, 感觉不错的话点个 [star](https://github.com/lxzan/gws) 支持吧
有疑问加站长微信联系(非本文作者)