forked from ikeikeikeike/go-sitemap-generator
/
options.go
126 lines (108 loc) · 3.67 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package stm
// NewOptions returns the created the Options's pointer
func NewOptions() *Options {
// Default values
return &Options{
defaultHost: "http://www.example.com",
sitemapsHost: "", // http://s3.amazonaws.com/sitemap-generator/,
alternativeSitemapsHosts: []string{},
publicPath: "public/",
sitemapsPath: "sitemaps",
filename: "sitemap",
verbose: true,
compress: true,
pretty: false,
adp: NewFileAdapter(),
}
}
// Options exists for the Sitemap struct.
type Options struct {
defaultHost string
sitemapsHost string
alternativeSitemapsHosts []string
publicPath string
sitemapsPath string
filename string
verbose bool
compress bool
pretty bool
adp Adapter
nmr *Namer
loc *Location
}
// SetDefaultHost sets that arg from Sitemap.Finalize method
func (opts *Options) SetDefaultHost(host string) {
opts.defaultHost = host
}
// SetSitemapsHost sets that arg from Sitemap.SetSitemapsHost method
func (opts *Options) SetSitemapsHost(host string) {
opts.sitemapsHost = host
}
// AddAlternativeSitemapsHosts adds that arg from Sitemap.AddAlternativeSitemapsHosts method
func (opts *Options) AddAlternativeSitemapsHost(host string) {
opts.alternativeSitemapsHosts = append(opts.alternativeSitemapsHosts, host)
}
// SetSitemapsPath sets that arg from Sitemap.SetSitemapsPath method.
func (opts *Options) SetSitemapsPath(path string) {
opts.sitemapsPath = path
}
// SetPublicPath sets that arg from Sitemap.SetPublicPath method
func (opts *Options) SetPublicPath(path string) {
opts.publicPath = path
}
// SetFilename sets that arg from Sitemap.SetFilename method
func (opts *Options) SetFilename(filename string) {
opts.filename = filename
}
// SetVerbose sets that arg from Sitemap.SetVerbose method
func (opts *Options) SetVerbose(verbose bool) {
opts.verbose = verbose
}
// SetCompress sets that arg from Sitemap.SetCompress method
func (opts *Options) SetCompress(compress bool) {
opts.compress = compress
}
// SetPretty option sets pretty option to Options struct which allows pretty formatting to output files.
func (opts *Options) SetPretty(pretty bool) {
opts.pretty = pretty
}
// SetAdapter sets that arg from Sitemap.SetAdapter method
func (opts *Options) SetAdapter(adp Adapter) {
opts.adp = adp
}
// SitemapsHost sets that arg from Sitemap.SitemapsHost method
func (opts *Options) SitemapsHost() string {
if opts.sitemapsHost != "" {
return opts.sitemapsHost
}
return opts.defaultHost
}
// AlternativeSitemapsHosts sets that arg from Sitemap.AlternativeSitemapsHosts method
func (opts *Options) AlternativeSitemapsHosts() []string {
return opts.alternativeSitemapsHosts
}
// Location returns the Location's pointer with
// set option to arguments for Builderfile struct.
func (opts *Options) Location() *Location {
return NewLocation(opts)
}
// IndexLocation returns the Location's pointer with
// set option to arguments for BuilderIndexfile struct.
func (opts *Options) IndexLocation() *Location {
o := opts.Clone()
o.nmr = NewNamer(&NOpts{base: opts.filename})
return NewLocation(o)
}
// Namer returns Namer's pointer cache. If didn't create that yet,
// It also returns created Namer's pointer.
func (opts *Options) Namer() *Namer {
if opts.nmr == nil {
opts.nmr = NewNamer(&NOpts{base: opts.filename, zero: 1, start: 2})
}
return opts.nmr
}
// Clone method returns it copied myself.
func (opts *Options) Clone() *Options {
o := *opts
return &o
}