/
link.go
39 lines (31 loc) · 893 Bytes
/
link.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
package commonxml
type Link struct {
HasAttributes
Rel string `xml:"rel,attr,omitempty" json:"rel,omitempty"`
Type string `xml:"type,attr,omitempty" json:"type,omitempty"`
Href string `xml:"href,attr" json:"href,omitempty"`
HrefLang string `xml:"hreflang,attr,omitempty" json:"hrefLang,omitempty"`
Template string `xml:"template,attr,omitempty" json:"template,omitempty"`
Title string `xml:"title,attr,omitempty" json:"title,omitempty"`
Length uint `xml:"length,attr,omitempty" json:"length,omitempty"`
}
type HasLinks struct {
Link []Link `xml:"link" json:"link,omitempty"`
}
func (v *HasLinks) GetLink(rel string) *Link {
for _, l := range v.Link {
if l.Rel == rel {
return &l
}
}
return nil
}
func (v *HasLinks) GetLinks(rel string) []Link {
var a []Link
for _, l := range v.Link {
if l.Rel == rel {
a = append(a, l)
}
}
return a
}