Documentation ¶
Overview ¶
Package sitemap provides primitives for high effective parsing of huge sitemap files.
Index ¶
- func Parse(reader io.Reader, consumer EntryConsumer) error
- func ParseFromFile(sitemapPath string, consumer EntryConsumer) error
- func ParseFromSite(url string, consumer EntryConsumer) error
- func ParseIndex(reader io.Reader, consumer IndexEntryConsumer) error
- func ParseIndexFromFile(sitemapPath string, consumer IndexEntryConsumer) error
- func ParseIndexFromSite(sitemapURL string, consumer IndexEntryConsumer) error
- type Entry
- type EntryConsumer
- type IndexEntry
- type IndexEntryConsumer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
func Parse(reader io.Reader, consumer EntryConsumer) error
Parse parses data which provides by the reader and for each sitemap entry calls the consumer's function.
func ParseFromFile ¶
func ParseFromFile(sitemapPath string, consumer EntryConsumer) error
ParseFromFile reads sitemap from a file, parses it and for each sitemap entry calls the consumer's function.
Example ¶
* Examples
err := ParseFromFile("./testdata/sitemap.xml", func(e Entry) error { fmt.Println(e.GetLocation()) return nil }) if err != nil { panic(err) }
Output:
func ParseFromSite ¶
func ParseFromSite(url string, consumer EntryConsumer) error
ParseFromSite downloads sitemap from a site, parses it and for each sitemap entry calls the consumer's function.
func ParseIndex ¶
func ParseIndex(reader io.Reader, consumer IndexEntryConsumer) error
ParseIndex parses data which provides by the reader and for each sitemap index entry calls the consumer's function.
func ParseIndexFromFile ¶
func ParseIndexFromFile(sitemapPath string, consumer IndexEntryConsumer) error
ParseIndexFromFile reads sitemap index from a file, parses it and for each sitemap index entry calls the consumer's function.
Example ¶
result := make([]string, 0, 0) err := ParseIndexFromFile("./testdata/sitemap-index.xml", func(e IndexEntry) error { result = append(result, e.GetLocation()) return nil }) if err != nil { panic(err) }
Output:
func ParseIndexFromSite ¶
func ParseIndexFromSite(sitemapURL string, consumer IndexEntryConsumer) error
ParseIndexFromSite downloads sitemap index from a site, parses it and for each sitemap index entry calls the consumer's function.
Types ¶
type Entry ¶
Entry is an interface describes an element \ an URL in the sitemap file. Keep in mind. It is implemented by a totally immutable entity so you should minimize calls count because it can produce additional memory allocations.
GetLocation returns URL of the page. GetLocation must return a non-nil and not empty string value.
GetLastModified parses and returns date and time of last modification of the page. GetLastModified can return nil or a valid time.Time instance. Be careful. Each call return new time.Time instance.
GetChangeFrequency returns string value indicates how frequent the page is changed. GetChangeFrequency returns non-nil string value. See Frequency consts set.
GetPriority return priority of the page. The valid value is between 0.0 and 1.0, the default value is 0.5.
You shouldn't implement this interface in your types.
type EntryConsumer ¶
EntryConsumer is a type represents consumer of parsed sitemaps entries
type IndexEntry ¶
IndexEntry is an interface describes an element \ an URL in a sitemap index file. Keep in mind. It is implemented by a totally immutable entity so you should minimize calls count because it can produce additional memory allocations.
GetLocation returns URL of a sitemap file. GetLocation must return a non-nil and not empty string value.
GetLastModified parses and returns date and time of last modification of sitemap. GetLastModified can return nil or a valid time.Time instance. Be careful. Each call return new time.Time instance.
You shouldn't implement this interface in your types.
type IndexEntryConsumer ¶
type IndexEntryConsumer func(IndexEntry) error
IndexEntryConsumer is a type represents consumer of parsed sitemaps indexes entries