Begin websocket client
This commit is contained in:
parent
c0448451e3
commit
52f00b341d
43
websocket/client.go
Normal file
43
websocket/client.go
Normal file
@ -0,0 +1,43 @@
|
||||
package websocket
|
||||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
const ENDPOINT = "wss://ws-feed.gdax.com"
|
||||
|
||||
type Client struct {
|
||||
Disconnect chan int
|
||||
|
||||
conn *websocket.Conn
|
||||
}
|
||||
|
||||
func NewClient() *Client {
|
||||
c := Client{}
|
||||
c.writer = make(chan string)
|
||||
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c *Client) Open() error {
|
||||
c.conn, _, err := websocket.Dial(ENDPOINT, nil)
|
||||
if err != nil {
|
||||
return erro
|
||||
}
|
||||
|
||||
go func () {
|
||||
var buf []byte
|
||||
for true {
|
||||
_, buf, _ = c.conn.ReadMessage()
|
||||
log.Write(string(bug))
|
||||
}
|
||||
}()
|
||||
|
||||
go func () {
|
||||
select {
|
||||
case message <- c.writer:
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user