-
Notifications
You must be signed in to change notification settings - Fork 0
/
url.go
63 lines (54 loc) · 1.49 KB
/
url.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
package sitemap
import (
"encoding/xml"
"time"
)
// Url is a url block to be nested under UrlSet.
type Url struct {
XMLName xml.Name `xml:"url,omitempty"`
Location string `xml:"loc,omitempty"`
ChangeFrequency string `xml:"changefreq,omitempty"`
Priority string `xml:"priority,omitempty"`
LastModifiedDate time.Time `xml:"lastmod,omitempty"`
News *News `xml:"news:news,omitempty"`
Images []*Image `xml:"image:image,omitempty"`
Videos []*Video `xml:"video:video,omitempty"`
}
// SetLocation sets the url's location parameter
func (u *Url) SetLocation(l string) *Url {
u.Location = l
return u
}
// SetLastModified sets the value of the modified date field.
func (u *Url) SetLastModified(t time.Time) *Url {
u.LastModifiedDate = t.UTC()
return u
}
// SetNews sets the news value.
func (u *Url) SetNews(n *News) *Url {
u.News = n
return u
}
// AddImage adds one or more image block value.
func (u *Url) AddImage(i ...*Image) *Url {
u.Images = append(u.Images, i...)
return u
}
// AddVideo adds one or more video block value.
func (u *Url) AddVideo(v ...*Video) *Url {
u.Videos = append(u.Videos, v...)
return u
}
// defaultUrl creates a default url entity with required values.
func defaultUrl() *Url {
now := time.Now()
url := &Url{
Images: make([]*Image, 0),
Videos: make([]*Video, 0),
}
return url.SetLastModified(now)
}
// NewUrl returns a new instance of the default URL.
func NewUrl() *Url {
return defaultUrl()
}