blob: 575bcd516b1f61dfe4d282124b767fcc76689c27 (
plain)
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
|
// Websocket debug tool
//
// Usage: ./websocket-linux-amd64 ws://<shelly-ip>/rpc
//
// This tools is intended to support development of the Websocket-based
// application programming interface (API) of the Shelly Internet of Things
// (IoT) devices.
package main
import (
"log"
"net/url"
"os"
"os/signal"
"github.com/gorilla/websocket"
)
func main() {
log.SetFlags(0)
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
var u url.URL = getURL()
log.Printf("connecting to %s", u.String())
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if (err != nil) {
log.Fatal(err)
}
defer c.Close()
}
func getURL() url.URL {
if (len(os.Args) != 2) {
log.Fatalf("Exactly one argument expected but got %d.", len(os.Args) - 1)
}
maybeURL, err := url.Parse(os.Args[1])
if (err != nil) {
log.Fatalf("Cannot parse given URL: %s", os.Args[1])
}
return *maybeURL
}
|