/
user.go
91 lines (83 loc) · 1.86 KB
/
user.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
90
91
package ulist
import (
"bytes"
"fmt"
"strings"
"text/template"
)
// User represents a participant in the ClosetSanta
type User struct {
Username string
ShareName bool
AgreeRules bool
RepSubreddit string
MessageToSanta string
Watchlist string
Address Address
Regift bool
International bool
match string
}
func (u *User) String() string {
// const fmtString = `
// Username: {{ .Username }}
// RepSubreddit: {{ .RepSubreddit }}
// Watchlist: {{ .Watchlist }}
// MessageToSanta:
// ---
// {{ .MessageToSanta }}
// ---
// AgreeRules: {{ printf "%t" .AgreeRules }}, ShareName: {{ printf "%t" .ShareName }}
// Regift: {{ printf "%t" .Regift }}, International: {{ printf "%t" .International }}
// Address:
// ---
// {{ .Address.String }}
// ---
// `
const fmtString = `
Username: {{ .Username }}
RepSubreddit: {{ .RepSubreddit }}
Watchlist: {{ .Watchlist }}
Address:
---
{{ .Address.String }}
---
AgreeRules: {{ printf "%t" .AgreeRules }}
ShareName: {{ printf "%t" .ShareName }}
Regift: {{ printf "%t" .Regift }}
International: {{ printf "%t" .International }}
MessageToSanta:
--
{{ .MessageToSanta }}
---
`
t := template.Must(template.New("fmt").Parse(fmtString))
var buf bytes.Buffer
if err := t.Execute(&buf, u); err != nil {
panic(err)
}
return buf.String()
}
func (u *User) GetMatch(ulist []User) *User {
for _, user := range ulist {
if u.match == user.Username {
return &user
}
}
return nil
}
type Address struct {
Fullname string
Street1 string
Street2 string
City string
State string
Country string
Zipcode string
}
func (a *Address) String() string {
return fmt.Sprintf("%v\n%v\n%v\n%v %v\n%v %v", a.Fullname, a.Street1, a.Street2, a.Zipcode, a.City, a.State, a.Country)
}
func CompareUsernames(u1, u2 string) bool {
return strings.ToLower(u1) == strings.ToLower(u2)
}