-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpers.go
More file actions
53 lines (48 loc) · 920 Bytes
/
Helpers.go
File metadata and controls
53 lines (48 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package WebsocketCryptoScraper
import (
"bytes"
"compress/gzip"
"encoding/json"
"fmt"
"io"
"io/ioutil"
)
//TODO should be part of Huobi handler
func prepSubmessage(subMessage string, id string) []byte {
v := HuobiSubscription{subMessage, id, "false"}
toSub, err := json.Marshal(v)
if err != nil {
panic(err)
}
return toSub
}
// convert reader to []byte
func streamToByte(stream io.Reader) []byte {
buf := new(bytes.Buffer)
buf.ReadFrom(stream)
return buf.Bytes()
}
// Unzip a reader to string
func Unzip(reader io.Reader) string {
r, err := gzip.NewReader(reader)
if err != nil {
panic(err)
}
defer r.Close()
buf, err := ioutil.ReadAll(r)
if err != nil {
panic(r)
}
return string(buf)
}
//Printer prints contents of a channel until a stop signal is given
func Printer(l chan ListenOut, stop chan bool) {
for {
select {
default:
fmt.Println(<-l)
case <-stop:
return
}
}
}