-
Notifications
You must be signed in to change notification settings - Fork 0
/
withArgs.go
77 lines (63 loc) · 1.4 KB
/
withArgs.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
package watch
import (
"net/smtp"
)
type WatchHandlerOption func(wh *watchHandler)
type watchHandler struct {
dev, sendEmail, sendSlack, sendDiscord bool
emailDetails EmailDetails
slackDetails SlackDetails
discordDetails DiscordDetails
debugPath string
}
type EmailDetails struct {
Addr string
A smtp.Auth
From string
To []string
}
type SlackDetails struct {
WebHookURL string
}
type DiscordDetails struct {
WebHookURL string
}
func newWatchHandler(opts []WatchHandlerOption) watchHandler {
wh := watchHandler{
dev: true,
sendEmail: false,
debugPath: "/watch/debug",
}
for _, opt := range opts {
opt(&wh)
}
return wh
}
func WithDevelopment(dev bool) WatchHandlerOption {
return func(wh *watchHandler) {
wh.dev = dev
}
}
func WithEmail(details EmailDetails) WatchHandlerOption {
return func(wh *watchHandler) {
wh.sendEmail = true
wh.emailDetails = details
}
}
func WithSlack(details SlackDetails) WatchHandlerOption {
return func(wh *watchHandler) {
wh.sendSlack = true
wh.slackDetails = details
}
}
func WithDiscord(details DiscordDetails) WatchHandlerOption {
return func(wh *watchHandler) {
wh.sendDiscord = true
wh.discordDetails = details
}
}
func WithDebugPath(path string) WatchHandlerOption {
return func(wh *watchHandler) {
wh.debugPath = path
}
}