44 lines
570 B
Go
44 lines
570 B
Go
|
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
|
||
|
}
|