diff --git a/etc/blockchain.yaml b/etc/blockchain.yaml index e965115..0a400f4 100644 --- a/etc/blockchain.yaml +++ b/etc/blockchain.yaml @@ -3,7 +3,7 @@ ListenOn: 0.0.0.0:8888 Timeout: 10000 Etcd: Hosts: - - 10.0.0.19:2379 + - localhost:2379 Key: blockchain.rpc Binance: Key: "" diff --git a/internal/lib/websocket/config.go b/internal/lib/websocket/config.go new file mode 100644 index 0000000..e8fafea --- /dev/null +++ b/internal/lib/websocket/config.go @@ -0,0 +1,27 @@ +package websocket + +import ( + "crypto/tls" + "github.com/lxzan/gws" + "net/http" + "time" +) + +type ClientOption struct { + WriteBufferSize int + PermessageDeflate gws.PermessageDeflate + ParallelEnabled bool + ParallelGoLimit int + ReadMaxPayloadSize int + ReadBufferSize int + WriteMaxPayloadSize int + CheckUtf8Enabled bool + Logger gws.Logger + Recovery func(logger gws.Logger) + Addr string + RequestHeader http.Header + HandshakeTimeout time.Duration + TlsConfig *tls.Config + NewDialer func() (gws.Dialer, error) + NewSession func() gws.SessionStorage +} diff --git a/internal/lib/websocket/connection.go b/internal/lib/websocket/connection.go new file mode 100644 index 0000000..3ed8ef8 --- /dev/null +++ b/internal/lib/websocket/connection.go @@ -0,0 +1,25 @@ +package websocket + +import ( + "github.com/lxzan/gws" + "net/url" +) + +type Connection struct { + *gws.Conn +} + +func NewWebSocketConnect(url url.URL, handler gws.Event) (*Connection, error) { + socket, _, err := gws.NewClient(handler, &gws.ClientOption{ + Addr: url.String(), + }) + if err != nil { + return nil, err + } + // 取得消息 + go socket.ReadLoop() + + return &Connection{ + socket, + }, nil +} diff --git a/internal/lib/websocket/option.go b/internal/lib/websocket/option.go new file mode 100644 index 0000000..708bc8c --- /dev/null +++ b/internal/lib/websocket/option.go @@ -0,0 +1 @@ +package websocket