Skip to content

Commit 90ea2ed

Browse files
Added functions to retrieve all values for an attribute at key
1 parent 23b0b0c commit 90ea2ed

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

attribute.go

+33
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,36 @@ func (vals Values) Get(k string) string {
1717
}
1818
return ""
1919
}
20+
21+
//GetSize returns the number of values for an attribute at a key.
22+
//Returns '0' in case of error or if key is not found.
23+
func (vals Values) GetSize(k string) int {
24+
if vals == nil {
25+
return 0
26+
}
27+
28+
v, ok := vals[k]
29+
if ok {
30+
return len(v.Values)
31+
}
32+
33+
return 0
34+
}
35+
36+
//GetAll returns all the values for an attribute at a key.
37+
//Returns an empty slice in case of error of if key is not found.
38+
func (vals Values) GetAll(k string) []string {
39+
var av []string
40+
41+
if vals == nil {
42+
return av
43+
}
44+
45+
if v, ok := vals[k]; ok && len(v.Values) > 0 {
46+
for i := 0; i < len(v.Values); i++ {
47+
av = append(av, string(v.Values[i].Value))
48+
}
49+
}
50+
51+
return av
52+
}

0 commit comments

Comments
 (0)