blob: 1ae13c63c1b01a33c59fe671936b1259c348d4bc (
plain)
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
|
package identity
import "strings"
type Identity struct {
Full string
Reduced string
}
func (i Identity) Is(input string) bool {
reduced := Reduce(input)
return i.Reduced == reduced
}
func New(input string) Identity {
reduced := Reduce(input)
return Identity{
Full: input,
Reduced: reduced,
}
}
func Reduce(input string) string {
reduced := input
if !strings.HasPrefix(reduced, ".") {
reduced = strings.Split(reduced, ".")[0]
}
reduced = strings.ToLower(reduced)
return reduced
}
|