Documentation
¶
Index ¶
- Variables
- func Fetch(ctx context.Context, url string, opts ...Option) <-chan ParseResult
- func FetchAll(ctx context.Context, urls []string, opts ...Option) <-chan ParseResult
- func Parse(ctx context.Context, reader io.Reader, opts ...Option) <-chan ParseResult
- func ParseFile(ctx context.Context, filepath string, opts ...Option) <-chan ParseResult
- func ParseTime(input string) (time.Time, error)
- type ChangeFreq
- type Filter
- type HTTPError
- type Option
- func WithBufferSize(n int) Option
- func WithChangeFreq() Option
- func WithCustomLexer() Option
- func WithLastMod() Option
- func WithMaxConcurrency(n int) Option
- func WithModifiedSince(t time.Time) Option
- func WithPriority() Option
- func WithSitemapFilter(f *Filter) Option
- func WithSitemapIndexFilter(f *Filter) Option
- type ParseResult
- type TimeParseError
Constants ¶
This section is empty.
Variables ¶
var (
ErrMalformedXML = errors.New("malformed xml")
)
Functions ¶
func Fetch ¶
func Fetch(ctx context.Context, url string, opts ...Option) <-chan ParseResult
Fetch retrieves entries from url, recursing into child sitemaps as needed.
func FetchAll ¶
func FetchAll(ctx context.Context, urls []string, opts ...Option) <-chan ParseResult
FetchAll fetches multiple URLs concurrently into a single combined stream.
Types ¶
type ChangeFreq ¶
type ChangeFreq string
ChangeFreq is the value of a sitemap entry's <changefreq> tag.
const ( ChangeFreqAlways ChangeFreq = "always" ChangeFreqHourly ChangeFreq = "hourly" ChangeFreqDaily ChangeFreq = "daily" ChangeFreqWeekly ChangeFreq = "weekly" ChangeFreqMonthly ChangeFreq = "monthly" ChangeFreqYearly ChangeFreq = "yearly" ChangeFreqNever ChangeFreq = "never" )
type Filter ¶
type Filter struct {
// Applied to the URI (path + query). If set, the URI must match at least one.
Whitelist []*regexp.Regexp
// Applied to the URI (path + query). If set, the URI must not match any.
Blacklist []*regexp.Regexp
// Applied to the full loc string, including the domain.
RawMatch *regexp.Regexp
}
Filter provides rules for filtering sitemap or index URLs.
type Option ¶
type Option func(*options)
Option configures the streaming functions in this package.
func WithBufferSize ¶
WithBufferSize overrides the output channel buffer size.
func WithChangeFreq ¶
func WithChangeFreq() Option
WithChangeFreq parses <changefreq> into Entry.ChangeFreq.
func WithCustomLexer ¶
func WithCustomLexer() Option
WithCustomLexer opts into a faster custom XML lexer instead of the standard library decoder.
func WithMaxConcurrency ¶
WithMaxConcurrency overrides the max number of concurrent fetches.
func WithModifiedSince ¶
WithModifiedSince drops entries modified before t, implies WithLastMod. Jalali time is converted to Gregorian automatically.
func WithSitemapFilter ¶
WithSitemapFilter applies a filter to sitemap entries.
func WithSitemapIndexFilter ¶
WithSitemapIndexFilter applies a filter to sitemap index entries.
type ParseResult ¶
type ParseResult struct {
Loc string
LastMod time.Time
ChangeFreq ChangeFreq
Priority float64
Err error
}
ParseResult represents a parsed sitemap entry or an error. Loc is always populated. Other fields are only populated if their corresponding With* option was provided; otherwise they remain zero-valued (or -1 for Priority).
type TimeParseError ¶
type TimeParseError struct {
Raw string
}
func (*TimeParseError) Error ¶
func (e *TimeParseError) Error() string