-
Notifications
You must be signed in to change notification settings - Fork 14
/
messages.go
68 lines (59 loc) · 1.35 KB
/
messages.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package lrserver
var protocols = []string{
"http://livereload.com/protocols/official-7",
"http://livereload.com/protocols/official-8",
"http://livereload.com/protocols/official-9",
"http://livereload.com/protocols/2.x-origin-version-negotiation",
"http://livereload.com/protocols/2.x-remote-control",
}
type clientHello struct {
Command string `json:"command"`
Protocols []string `json:"protocols"`
}
func validateHello(hello *clientHello) bool {
if hello.Command != "hello" {
return false
}
for _, c := range hello.Protocols {
for _, s := range protocols {
if c == s {
return true
}
}
}
return false
}
type serverHello struct {
Command string `json:"command"`
Protocols []string `json:"protocols"`
ServerName string `json:"serverName"`
}
func makeServerHello(name string) *serverHello {
return &serverHello{
"hello",
protocols,
name,
}
}
type serverReload struct {
Command string `json:"command"`
Path string `json:"path"`
LiveCSS bool `json:"liveCSS"`
}
func makeServerReload(file string, liveCSS bool) *serverReload {
return &serverReload{
Command: "reload",
Path: file,
LiveCSS: liveCSS,
}
}
type serverAlert struct {
Command string `json:"command"`
Message string `json:"message"`
}
func makeServerAlert(msg string) *serverAlert {
return &serverAlert{
Command: "alert",
Message: msg,
}
}