master
Raw Download raw file
 1package main
 2
 3import (
 4	"encoding/json"
 5	"fmt"
 6	"github.com/gorilla/websocket"
 7	"time"
 8)
 9
10func Connect(url string) (c *websocket.Conn, err error) {
11	dialer := &websocket.Dialer{}
12	dialer.EnableCompression = false
13	c, _, err = dialer.Dial(url, nil)
14	if err != nil {
15		return c, err
16	}
17	return c, err
18}
19
20type Place struct {
21	Type         string `json:"type"`
22	PlacePayload `json:"payload"`
23}
24type PlacePayload struct {
25	Y      int       `json:"y"`
26	X      int       `json:"x"`
27	Color  int       `json:"color"`
28	Author string    `json:"author"`
29	Date   time.Time `json:"date"`
30}
31
32const URL = "YOUR WSS URL HERE"
33
34func main() {
35	c, _ := Connect(URL)
36	for {
37		_, packet, err := c.ReadMessage()
38		if err != nil {
39			fmt.Println(err)
40			continue
41		}
42
43		var p Place
44		err := json.Unmarshal(packet, &p)
45		if err != nil {
46			panic(err)
47		}
48
49		p.Date = time.Now()
50		pStr, _ := json.Marshal(p)
51		fmt.Println(string(pStr))
52	}
53}