-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.go
40 lines (36 loc) · 964 Bytes
/
example.go
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
package main
import (
"flag"
"fmt"
"log"
"net/url"
"os"
"github.com/gorilla/websocket"
"github.com/tidwall/gjson"
)
var (
addr = flag.String("addr", "www.bet365data.com", "http service address")
token = flag.String("token", "", "your token")
path = flag.String("path", "/ws/inplayFootBall/en", "your path") //en=English|cn =Chinese
dialer *websocket.Dialer
)
func main() {
u := url.URL{Scheme: "wss", Host: *addr, Path: *path, RawQuery: fmt.Sprintf("token=%s", *token)}
conn, _, err := dialer.Dial(u.String(), nil)
if err != nil {
log.Panic(err)
os.Exit(-1)
}
for {
_, message, err := conn.ReadMessage()
if err != nil {
log.Println("read:", err)
return
}
if gjson.GetBytes(message, "code").Int() == 0 {
fmt.Println(gjson.GetBytes(message, "channel")) //inplay
fmt.Println(gjson.GetBytes(message, "typs")) //event|list|detail|live_animation|media
fmt.Println(gjson.GetBytes(message, "data")) //map
}
}
}