-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_welcome_email.go
56 lines (45 loc) · 987 Bytes
/
01_welcome_email.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
package constructor_injection
import (
"errors"
)
func NewWelcomeSender(in *Mailer) (*WelcomeSender, error) {
// guard clause
if in == nil {
return nil, errors.New("programmer error: mailer must not provided")
}
return &WelcomeSender{
mailer: in,
}, nil
}
func NewWelcomeSenderNoGuard(in *Mailer) *WelcomeSender {
return &WelcomeSender{
mailer: in,
}
}
// WelcomeSender sends a Welcome email to new users
type WelcomeSender struct {
mailer *Mailer
}
func (w *WelcomeSender) Send(to string) error {
body := w.buildMessage()
return w.mailer.Send(to, body)
}
// build and return the message body
func (w *WelcomeSender) buildMessage() string {
return ""
}
// Mailer sends and receives emails
type Mailer struct {
Host string
Port string
Username string
Password string
}
func (m *Mailer) Send(to string, body string) error {
// send email
return nil
}
func (m *Mailer) Receive(address string) (string, error) {
// receive email
return "", nil
}