-
Notifications
You must be signed in to change notification settings - Fork 6
/
shout.go
84 lines (72 loc) · 1.63 KB
/
shout.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package backend
import (
"fmt"
"net/url"
"time"
shout "github.com/thomasmitchell/go-shout"
)
type ShoutConfig struct {
URL string `yaml:"url"`
Topic string `yaml:"topic"`
Username string `yaml:"username"`
Password string `yaml:"password"`
}
type Shout struct {
client shout.Client
topic string
doomsdayDomain string
}
func newShoutBackend(c ShoutConfig, uni BackendUniversalConfig) (*Shout, error) {
if c.URL == "" {
return nil, fmt.Errorf("No URL provided")
}
if c.Topic == "" {
return nil, fmt.Errorf("No topic name provided")
}
if c.Username == "" {
return nil, fmt.Errorf("No username provided")
}
if c.Password == "" {
return nil, fmt.Errorf("No password provided")
}
if u, err := url.Parse(c.URL); err != nil || u.Host == "" {
return nil, fmt.Errorf("URL not parsable")
}
return &Shout{
client: shout.Client{
Target: c.URL,
Username: c.Username,
Password: c.Password,
Trace: uni.Logger,
},
topic: c.Topic,
doomsdayDomain: uni.DoomsdayURL,
}, nil
}
func (s Shout) OK() error {
return s.client.PostEvent(shout.EventIn{
Topic: s.topic,
Message: msgOK,
Link: s.doomsdayDomain,
OccurredAt: time.Now(),
OK: true,
})
}
func (s Shout) Soon() error {
return s.client.PostEvent(shout.EventIn{
Topic: s.topic,
Message: msgSoon,
Link: s.doomsdayDomain,
OccurredAt: time.Now(),
OK: false,
})
}
func (s Shout) Expired() error {
return s.client.PostEvent(shout.EventIn{
Topic: s.topic,
Message: msgExpired,
Link: s.doomsdayDomain,
OccurredAt: time.Now(),
OK: false,
})
}