-
Notifications
You must be signed in to change notification settings - Fork 5
/
options.go
104 lines (91 loc) · 2.08 KB
/
options.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package podcasts
import (
"errors"
"net/url"
)
var (
// ErrInvalidURL represents a error returned for invalid url.
ErrInvalidURL = errors.New("podcasts: invalid url")
// ErrInvalidImage represents a error returned for invalid image.
ErrInvalidImage = errors.New("podcasts: invalid image")
)
const (
// ValueYes represents positive value used in XML feed.
ValueYes = "yes"
)
// Author sets itunes:author of given feed.
func Author(author string) func(f *Feed) error {
return func(f *Feed) error {
f.Channel.Author = author
return nil
}
}
// Block enables itunes:block of given feed.
func Block(f *Feed) error {
f.Channel.Block = ValueYes
return nil
}
// Explicit enables itunes:explicit of given feed.
func Explicit(f *Feed) error {
f.Channel.Explicit = ValueYes
return nil
}
// Complete enables itunes:complete of given feed.
func Complete(f *Feed) error {
f.Channel.Complete = ValueYes
return nil
}
// NewFeedURL sets itunes:new-feed-url of given feed.
func NewFeedURL(newURL string) func(f *Feed) error {
return func(f *Feed) error {
u, err := url.Parse(newURL)
if err != nil {
return err
}
if !u.IsAbs() {
return ErrInvalidURL
}
f.Channel.NewFeedURL = newURL
return nil
}
}
// Subtitle sets itunes:subtitle of given feed.
func Subtitle(subtitle string) func(f *Feed) error {
return func(f *Feed) error {
f.Channel.Subtitle = subtitle
return nil
}
}
// Summary sets itunes:summary of given feed.
func Summary(summary string) func(f *Feed) error {
return func(f *Feed) error {
f.Channel.Summary = &ItunesSummary{summary}
return nil
}
}
// Owner sets itunes:owner of given feed.
func Owner(name string, email string) func(f *Feed) error {
return func(f *Feed) error {
f.Channel.Owner = &ItunesOwner{
Name: name,
Email: email,
}
return nil
}
}
// Image sets itunes:image of given feed.
func Image(href string) func(f *Feed) error {
return func(f *Feed) error {
u, err := url.Parse(href)
if err != nil {
return err
}
if !u.IsAbs() {
return ErrInvalidImage
}
f.Channel.Image = &ItunesImage{
Href: href,
}
return nil
}
}