-
Notifications
You must be signed in to change notification settings - Fork 5
/
base_profile.go
54 lines (47 loc) · 1.52 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
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
}
// 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
}