Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrTooManyRequests = errors.New("429 Too Many Requests") ErrBadRequest = errors.New("400 Bad Request") ErrNotFound = errors.New("404 Not Found") ErrForbidden = errors.New("403 Forbidden") )
var (
ErrEmptyLoc = errors.New("empty loc")
)
var (
ErrInvalidChangeFrequency = errors.New("invalid changefreq")
)
var (
ErrInvalidFormat = errors.New("invalid format")
)
var (
ErrNotURLSet = errors.New("not urlset")
)
Functions ¶
This section is empty.
Types ¶
type ChangeFrequency ¶ added in v0.2.0
type ChangeFrequency byte
ChangeFrequency type used for the <changefreq> field
var ( ChangeFreqAlways ChangeFrequency = 1 // "always" ChangeFreqHourly ChangeFrequency = 2 // "hourly" ChangeFreqDaily ChangeFrequency = 3 // "daily" ChangeFreqWeekly ChangeFrequency = 4 // "weekly" ChangeFreqMonthly ChangeFrequency = 5 // "monthly" ChangeFreqYearly ChangeFrequency = 6 // "yearly" ChangeFreqNever ChangeFrequency = 7 // "never" )
Valid values for ChangeFrequency
func ParseChangeFreq ¶ added in v0.2.0
func ParseChangeFreq(v string) ChangeFrequency
ParseChangeFreq parses ChangeFrequency from v.
If v is not a valid ChangeFrequency, returns ChangeFrequency(255)
func (ChangeFrequency) IsEmpty ¶ added in v0.2.0
func (f ChangeFrequency) IsEmpty() bool
func (ChangeFrequency) IsSet ¶ added in v0.2.0
func (f ChangeFrequency) IsSet() bool
func (ChangeFrequency) MarshalXML ¶ added in v0.2.0
func (f ChangeFrequency) MarshalXML(e *xml.Encoder, start xml.StartElement) error
func (ChangeFrequency) String ¶ added in v0.2.0
func (f ChangeFrequency) String() string
String returns the string value of ChangeFrequency.
If f is not a valid ChangeFrequency, returns the value ChangeFrequency as a string.
func (*ChangeFrequency) UnmarshalXML ¶ added in v0.2.0
func (f *ChangeFrequency) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
UnmarshalXML implements the xml.Unmarshaler interface
type ContentTypeError ¶ added in v0.2.0
type ContentTypeError struct {
ContentType string
}
func NewContentTypeError ¶ added in v0.2.0
func NewContentTypeError(ct string) ContentTypeError
func (ContentTypeError) Error ¶ added in v0.2.0
func (cte ContentTypeError) Error() string
type Format ¶ added in v0.2.0
type Format byte
func FetchFormat ¶
FetchFormat downloads the XML from the url, unmarshals it and returns the sitemap format and the downloaded data. The format is either FormatURLSet or FormatIndex.
If invalid format found, returns ErrorInvalidFormat
Example ¶
f, _, err := sitemap.FetchFormat("https://gorbe.io/sitemap.xml") if err != nil { // handle error } fmt.Printf("%s\n", f) // "urlset"
Output:
func GetFormat ¶
GetFormat unmarshals the XML data and returns the sitemap format. The format is either FormatURLSet or FormatIndex.
If invalid format found, returns ErrorInvalidFormat
Example ¶
data := []byte(` <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>http://www.example.com/</loc> <lastmod>2005-01-01</lastmod> <changefreq>monthly</changefreq> <priority>0.8</priority> </url> </urlset>`) f, err := sitemap.GetFormat(data) if err != nil { // handle error } fmt.Printf("%s\n", f) // "urlset"
Output:
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
func FetchIndex ¶ added in v0.2.0
func (*Index) MarshalXML ¶ added in v0.2.0
func (*Index) UnmarshalXML ¶ added in v0.2.0
type LastModification ¶ added in v0.2.0
type LastModification int64
LastModification is the <lastmod> field stored in Unix timestamp.
func ParseLastModification ¶ added in v0.2.0
func ParseLastModification(s string) (LastModification, error)
func (LastModification) IsEmpty ¶ added in v0.2.0
func (t LastModification) IsEmpty() bool
func (LastModification) MarshalXML ¶ added in v0.2.0
func (l LastModification) MarshalXML(e *xml.Encoder, start xml.StartElement) error
func (LastModification) String ¶ added in v0.2.0
func (t LastModification) String() string
func (*LastModification) UnmarshalXML ¶ added in v0.2.0
func (t *LastModification) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
UnmarshalXML implements the xml.Unmarshaler interface
type Location ¶
type Location []byte
Location type used for the <loc> field
func (Location) MarshalXML ¶ added in v0.2.0
func (*Location) UnmarshalXML ¶
UnmarshalXML implements the xml.Unmarshaler interface
type Priority ¶
type Priority float64
Priority type used for the priority field
func (Priority) MarshalXML ¶ added in v0.2.0
func (*Priority) UnmarshalXML ¶
UnmarshalXML implements the xml.Unmarshaler interface
type Sitemap ¶
type Sitemap struct {
// contains filtered or unexported fields
}
func FetchSitemap ¶ added in v0.2.0
func FetchSitemaps ¶ added in v0.2.0
func NewSitemap ¶ added in v0.2.0
func (*Sitemap) MarshalXML ¶ added in v0.2.0
func (*Sitemap) UnmarshalXML ¶ added in v0.2.0
type URL ¶
type URL struct { Loc Location `xml:"loc"` LastMod LastModification `xml:"lastmod,omitempty"` ChangeFreq ChangeFrequency `xml:"changefreq,omitempty"` Priority Priority `xml:"priority,omitempty"` }