-
Notifications
You must be signed in to change notification settings - Fork 0
/
customer.go
63 lines (49 loc) · 1 KB
/
customer.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
package domain
import (
"net/mail"
)
type EmailAddress string
func NewEmailAddress(v string) (EmailAddress, error) {
re := EmailAddress(v)
if err := re.Validate(); err != nil {
return re, err
}
return re, nil
}
func (a EmailAddress) String() string {
return string(a)
}
func (a EmailAddress) Validate() error {
_, err := mail.ParseAddress(a.String())
if err != nil {
return err
}
return nil
}
type CustomerEmail interface {
String() EmailAddress
}
type UnverifiedEmail EmailAddress
func NewUnverifiedEmail(v EmailAddress) CustomerEmail {
_v := UnverifiedEmail(v)
return &_v
}
func (a *UnverifiedEmail) String() EmailAddress {
return EmailAddress(*a)
}
type VerifiedEmail EmailAddress
func NewVerifiedEmail(v EmailAddress) CustomerEmail {
_v := VerifiedEmail(v)
return &_v
}
func (a *VerifiedEmail) String() EmailAddress {
return EmailAddress(*a)
}
type Customer struct {
Email CustomerEmail
}
func NewCustomer(e EmailAddress) Customer {
return Customer{
Email: NewUnverifiedEmail(e),
}
}