-
Notifications
You must be signed in to change notification settings - Fork 0
/
human.go
89 lines (76 loc) · 1.51 KB
/
human.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
85
86
87
88
89
package types
import (
"github.com/google/uuid"
"sort"
"strings"
)
type Human struct {
UUID string
Names []string
Emails []string
Passwords []string
Roles []string
}
func NewHuman() *Human {
return &Human{UUID: uuid.New().String()}
}
func (h *Human) AddEmail(email string) {
email = strings.ToLower(strings.Trim(email, "“” "))
for _, e := range h.Emails {
if email == e {
// we already have that email
return
}
}
h.Emails = append(h.Emails, strings.ToLower(email))
sort.Strings(h.Emails)
}
func (h *Human) AddName(name string) {
name = strings.TrimSpace(name)
if len(name) == 0 {
return
}
for _, n := range h.Names {
if strings.EqualFold(name, n) {
// we already have that name
return
}
}
h.Names = append(h.Names, name)
sort.Strings(h.Names)
}
func (h *Human) AddRole(roleName string) {
roleName = strings.TrimSpace(roleName)
if len(roleName) == 0 {
return
}
for _, n := range h.Roles {
if strings.EqualFold(roleName, n) {
// we already have that name
return
}
}
h.Roles = append(h.Roles, roleName)
sort.Strings(h.Roles)
}
func (h *Human) AddPassword(password string) {
if len(password) == 0 {
return
}
for _, p := range h.Passwords {
if password == p {
// we already have that password
return
}
}
h.Passwords = append(h.Passwords, password)
sort.Strings(h.Passwords)
}
func (h *Human) Merge(otherHuman *Human) {
for _, e := range otherHuman.Emails {
h.AddEmail(e)
}
for _, n := range otherHuman.Names {
h.AddName(n)
}
}