-
Notifications
You must be signed in to change notification settings - Fork 5
/
base_profile.go
75 lines (66 loc) · 2.26 KB
/
base_profile.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
package profile
import (
"github.com/getyoti/yoti-go-sdk/v3/profile/attribute"
"github.com/getyoti/yoti-go-sdk/v3/yotiprotoattr"
)
type baseProfile struct {
attributeSlice []*yotiprotoattr.Attribute
}
// GetAttribute retrieve an attribute by name on the Yoti profile. Will return nil if attribute is not present.
func (p baseProfile) GetAttribute(attributeName string) *attribute.GenericAttribute {
for _, a := range p.attributeSlice {
if a.Name == attributeName {
return attribute.NewGeneric(a)
}
}
return nil
}
// GetAttributeByID retrieve an attribute by ID on the Yoti profile. Will return nil if attribute is not present.
func (p baseProfile) GetAttributeByID(attributeID string) *attribute.GenericAttribute {
for _, a := range p.attributeSlice {
if a.EphemeralId == attributeID {
return attribute.NewGeneric(a)
}
}
return nil
}
// GetAttributes retrieve a list of attributes by name on the Yoti profile. Will return an empty list of attribute is not present.
func (p baseProfile) GetAttributes(attributeName string) []*attribute.GenericAttribute {
var attributes []*attribute.GenericAttribute
for _, a := range p.attributeSlice {
if a.Name == attributeName {
attributes = append(attributes, attribute.NewGeneric(a))
}
}
return attributes
}
// GetStringAttribute retrieves a string attribute by name. Will return nil if attribute is not present.
func (p baseProfile) GetStringAttribute(attributeName string) *attribute.StringAttribute {
for _, a := range p.attributeSlice {
if a.Name == attributeName {
return attribute.NewString(a)
}
}
return nil
}
// GetImageAttribute retrieves an image attribute by name. Will return nil if attribute is not present.
func (p baseProfile) GetImageAttribute(attributeName string) *attribute.ImageAttribute {
for _, a := range p.attributeSlice {
if a.Name == attributeName {
imageAttribute, err := attribute.NewImage(a)
if err == nil {
return imageAttribute
}
}
}
return nil
}
// GetJSONAttribute retrieves a JSON attribute by name. Will return nil if attribute is not present.
func (p baseProfile) GetJSONAttribute(attributeName string) (*attribute.JSONAttribute, error) {
for _, a := range p.attributeSlice {
if a.Name == attributeName {
return attribute.NewJSON(a)
}
}
return nil, nil
}