Documentation ¶
Index ¶
- Constants
- Variables
- type BoolStr
- type ChildNode
- type Image
- type Lang
- type News
- type ParentNode
- type Platform
- type PlatformName
- type Publication
- type Restriction
- type Sitemap
- type SitemapIndex
- type SitemapXML
- func (s *SitemapXML) AddEntry(e ChildNode)
- func (s *SitemapXML) Output() ([]byte, error)
- func (s *SitemapXML) OutputPrettyString(prefix, indent string) (string, error)
- func (s *SitemapXML) OutputString() (string, error)
- func (s *SitemapXML) PrettyFormat(prefix, indent string)
- func (s *SitemapXML) SetType(t *xml.Attr)
- type Uploader
- type Url
- type UrlSet
- type Video
- func (v *Video) AllowCountries(c string) *Video
- func (v *Video) AllowPlatforms(p ...PlatformName) *Video
- func (v *Video) DenyCountries(c string) *Video
- func (v *Video) DenyPlatforms(p ...PlatformName) *Video
- func (v *Video) IsFamilyFriendly() *Video
- func (v *Video) IsLive() *Video
- func (v *Video) NotFamilyFriendly() *Video
- func (v *Video) NotLive() *Video
- func (v *Video) SetContentLoc(c string) *Video
- func (v *Video) SetDescription(d string) *Video
- func (v *Video) SetDuration(d int) *Video
- func (v *Video) SetExpirationDate(t time.Time) *Video
- func (v *Video) SetPlayerLoc(p string) *Video
- func (v *Video) SetPublicationDate(t time.Time) *Video
- func (v *Video) SetRating(r float32) *Video
- func (v *Video) SetTags(t ...string) *Video
- func (v *Video) SetThumbnailLoc(t string) *Video
- func (v *Video) SetTitle(t string) *Video
- func (v *Video) SetUploader(u *Uploader) *Video
- func (v *Video) SetUploaderInfo(i string) *Video
- func (v *Video) SetUploaderVal(val string) *Video
- func (v *Video) SetViewCount(vc int) *Video
- func (v *Video) SubNotRequired() *Video
- func (v *Video) SubRequired() *Video
Examples ¶
Constants ¶
const ( // TagLimit is the number of permitted video tags. TagLimit = 32 // MaxDescriptionLength is the maximum length of the video:description. MaxDescriptionLength = 2048 // DurationMin is the minimum video duration of 1 second. DurationMin int = 1 // DurationMax is the maximum video duration length in seconds (8 hours). DurationMax int = 28800 // RatingLow is the lowest posible rating. RatingLow float32 = 0.0 // RatingHigh is the highest posible rating. RatingHigh float32 = 5.0 )
Variables ¶
var ( // Allow is the allow attribute. Allow = &xml.Attr{ Name: xml.Name{Local: "relationship"}, Value: "allow", } // Deny is the deny attribute. Deny = &xml.Attr{ Name: xml.Name{Local: "relationship"}, Value: "deny", } )
var ( // XMLNSDefault is the default XML Namespace type. XMLNSDefault = &xml.Attr{ Name: xml.Name{Local: "xmlns"}, Value: "http://www.sitemaps.org/schemas/sitemap/0.9", } // XMLNSNews is the XML Namespace type for news. XMLNSNews = &xml.Attr{ Name: xml.Name{Local: "xmlns:news"}, Value: "http://www.google.com/schemas/sitemap-news/0.9", } // XMLNSXHTML is the XML Namespace type for XHTML. XMLNSXHTML = &xml.Attr{ Name: xml.Name{Local: "xmlns"}, Value: "http://www.w3.org/1999/xhtml", } // XMLNSMobile is the XML Namespace type for mobile-only content. XMLNSMobile = &xml.Attr{ Name: xml.Name{Local: "xmlns:mobile"}, Value: "http://www.google.com/schemas/sitemap-mobile/1.0", } // XMLNSImage is the XML Namespace type for images. XMLNSImage = &xml.Attr{ Name: xml.Name{Local: "xmlns:image"}, Value: "http://www.google.com/schemas/sitemap-image/1.1", } // XMLNSVideo is the XML Namespace type for videos. XMLNSVideo = &xml.Attr{ Name: xml.Name{Local: "xmlns:image"}, Value: "http://www.google.com/schemas/sitemap-video/1.1", } )
Functions ¶
This section is empty.
Types ¶
type ChildNode ¶ added in v1.1.1
type ChildNode interface { SetLocation(l string) SetLastModified(t time.Time) SetNews(n *News) AddImage(i ...*Image) AddVideo(v ...*Video) }
Childnode is the nested node type e.g. <url> or <sitemap>
func NewSitemap ¶ added in v1.1.0
func NewSitemap() ChildNode
NewSitemap returns a new instance of the default sitemap.
type Image ¶
type Image struct { XMLName xml.Name `xml:"image:image"` // Loc is the location of the image Loc string `xml:"image:loc"` }
Image stores image entry data.
type Lang ¶
type Lang string
const ( // 'en' is the default language. LanguageDefault Lang = Language_EN Language_AA Lang = "aa" Language_AB Lang = "ab" Language_AE Lang = "ae" Language_AF Lang = "af" Language_AK Lang = "ak" Language_AM Lang = "am" Language_AN Lang = "an" Language_AR Lang = "ar" Language_AS Lang = "as" Language_AV Lang = "av" Language_AY Lang = "ay" Language_AZ Lang = "az" Language_BA Lang = "ba" Language_BE Lang = "be" Language_BG Lang = "bg" Language_BH Lang = "bh" Language_BI Lang = "bi" Language_BM Lang = "bm" Language_BN Lang = "bn" Language_BO Lang = "bo" Language_BR Lang = "br" Language_BS Lang = "bs" Language_CA Lang = "ca" Language_CE Lang = "ce" Language_CH Lang = "ch" Language_CO Lang = "co" Language_CR Lang = "cr" Language_CS Lang = "cs" Language_CU Lang = "cu" Language_CV Lang = "cv" Language_CY Lang = "cy" Language_DA Lang = "da" Language_DE Lang = "de" Language_DV Lang = "dv" Language_DZ Lang = "dz" Language_EE Lang = "ee" Language_EL Lang = "el" Language_EN Lang = "en" Language_EO Lang = "eo" Language_ES Lang = "es" Language_ET Lang = "et" Language_EU Lang = "eu" Language_FA Lang = "fa" Language_FF Lang = "ff" Language_FI Lang = "fi" Language_FJ Lang = "fj" Language_FO Lang = "fo" Language_FR Lang = "fr" Language_FY Lang = "fy" Language_GA Lang = "ga" Language_GD Lang = "gd" Language_GL Lang = "gl" Language_GN Lang = "gn" Language_GU Lang = "gu" Language_GV Lang = "gv" Language_HA Lang = "ha" Language_HE Lang = "he" Language_HI Lang = "hi" Language_HO Lang = "ho" Language_HR Lang = "hr" Language_HT Lang = "ht" Language_HU Lang = "hu" Language_HY Lang = "hy" Language_HZ Lang = "hz" Language_IA Lang = "ia" Language_ID Lang = "id" Language_IE Lang = "ie" Language_IG Lang = "ig" Language_II Lang = "ii" Language_IK Lang = "ik" Language_IO Lang = "io" Language_IS Lang = "is" Language_IT Lang = "it" Language_IU Lang = "iu" Language_JA Lang = "ja" Language_JV Lang = "jv" Language_KA Lang = "ka" Language_KG Lang = "kg" Language_KI Lang = "ki" Language_KJ Lang = "kj" Language_KK Lang = "kk" Language_KL Lang = "kl" Language_KM Lang = "km" Language_KN Lang = "kn" Language_KO Lang = "ko" Language_KR Lang = "kr" Language_KS Lang = "ks" Language_KU Lang = "ku" Language_KV Lang = "kv" Language_KW Lang = "kw" Language_KY Lang = "ky" Language_LA Lang = "la" Language_LB Lang = "lb" Language_LG Lang = "lg" Language_LI Lang = "li" Language_LN Lang = "ln" Language_LO Lang = "lo" Language_LT Lang = "lt" Language_LU Lang = "lu" Language_LV Lang = "lv" Language_MG Lang = "mg" Language_MH Lang = "mh" Language_MI Lang = "mi" Language_MK Lang = "mk" Language_ML Lang = "ml" Language_MN Lang = "mn" Language_MR Lang = "mr" Language_MS Lang = "ms" Language_MT Lang = "mt" Language_MY Lang = "my" Language_NA Lang = "na" Language_NB Lang = "nb" Language_ND Lang = "nd" Language_NE Lang = "ne" Language_NG Lang = "ng" Language_NL Lang = "nl" Language_NN Lang = "nn" Language_NO Lang = "no" Language_NR Lang = "nr" Language_NV Lang = "nv" Language_NY Lang = "ny" Language_OC Lang = "oc" Language_OJ Lang = "oj" Language_OM Lang = "om" Language_OR Lang = "or" Language_OS Lang = "os" Language_PA Lang = "pa" Language_PI Lang = "pi" Language_PL Lang = "pl" Language_PS Lang = "ps" Language_PT Lang = "pt" Language_QU Lang = "qu" Language_RM Lang = "rm" Language_RN Lang = "rn" Language_RO Lang = "ro" Language_RU Lang = "ru" Language_RW Lang = "rw" Language_SA Lang = "sa" Language_SC Lang = "sc" Language_SD Lang = "sd" Language_SE Lang = "se" Language_SG Lang = "sg" Language_SI Lang = "si" Language_SK Lang = "sk" Language_SL Lang = "sl" Language_SM Lang = "sm" Language_SN Lang = "sn" Language_SO Lang = "so" Language_SQ Lang = "sq" Language_SR Lang = "sr" Language_SS Lang = "ss" Language_ST Lang = "st" Language_SU Lang = "su" Language_SV Lang = "sv" Language_SW Lang = "sw" Language_TA Lang = "ta" Language_TE Lang = "te" Language_TG Lang = "tg" Language_TH Lang = "th" Language_TI Lang = "ti" Language_TK Lang = "tk" Language_TL Lang = "tl" Language_TN Lang = "tn" Language_TO Lang = "to" Language_TR Lang = "tr" Language_TS Lang = "ts" Language_TT Lang = "tt" Language_TW Lang = "tw" Language_TY Lang = "ty" Language_UG Lang = "ug" Language_UK Lang = "uk" Language_UR Lang = "ur" Language_UZ Lang = "uz" Language_VE Lang = "ve" Language_VI Lang = "vi" Language_VO Lang = "vo" Language_WA Lang = "wa" Language_WO Lang = "wo" Language_XH Lang = "xh" Language_YI Lang = "yi" Language_YO Lang = "yo" Language_ZA Lang = "za" Language_ZH Lang = "zh" Language_ZU Lang = "zu" )
type News ¶
type News struct { XMLName xml.Name `xml:"news:news"` Name string `xml:"news:name"` Publication *Publication `xml:"news:publication"` PublicationDate time.Time `xml:"news:publication_date"` Title string `xml:"news:title"` }
News stores news entry data.
func (*News) SetLanguage ¶
SetLanguage sets the news extensions Publication.NewsLanguage parameter. Must be Lang.
func (*News) SetPublicationDate ¶
SetPublicationDate sets the news extensions PublicationDate parameter.
type ParentNode ¶ added in v1.1.1
ParentNode is the primary node e.g. <urlset> or <sitemap_index>
func NewIndex ¶ added in v1.1.1
func NewIndex() ParentNode
NewIndex returns a new instance of the default SitemapIndex.
func NewUrlSet ¶
func NewUrlSet() ParentNode
NewUrlSet returns a new instance of the default UrlSet.
type Platform ¶
type Platform struct { XMLName xml.Name `xml:"video:restriction,omitempty"` Relationship *xml.Attr `xml:",attr,omitempty"` Value string `xml:",chardata"` }
Platform stores allowed and restricted platforms.
type PlatformName ¶
type PlatformName string
PlatformName is a string name for a platform.
const ( Web PlatformName = "web" Mobile PlatformName = "mobile" TV PlatformName = "tv" )
type Publication ¶
type Publication struct { XMLName xml.Name `xml:"news:publication"` NewsName string `xml:"news:name,omitempty"` NewsLanguage Lang `xml:"news:language,omitempty"` }
Publication is the news publication sub-component to News.
type Restriction ¶
type Restriction struct { XMLName xml.Name `xml:"video:restriction,omitempty"` Relationship *xml.Attr `xml:",attr,omitempty"` Value string `xml:",chardata"` }
Restriction stores country restriction details
type Sitemap ¶ added in v1.1.0
type Sitemap struct { XMLName xml.Name `xml:"sitemap,omitempty"` Location string `xml:"loc,omitempty"` LastModifiedDate time.Time `xml:"lastmod,omitempty"` }
Sitemap is a sitemap block to be nested under SitemapIndex.
func (*Sitemap) SetLastModified ¶ added in v1.1.0
SetLastModified sets the value of the modified date field.
func (*Sitemap) SetLocation ¶ added in v1.1.0
SetLocation sets the sitemap's location parameter
type SitemapIndex ¶ added in v1.1.0
type SitemapIndex struct { XMLName xml.Name `xml:"sitemapindex"` Attributes []*xml.Attr `xml:",attr,omitempty"` Sitemap []ChildNode `xml:"sitemap,omitempty"` }
SitemapIndex is the primary sitemap index node.
func (*SitemapIndex) AddEntry ¶ added in v1.1.1
func (s *SitemapIndex) AddEntry(sm ChildNode)
AddEntry inserts a sitemap node into the XML's Sitemap node.
func (*SitemapIndex) SetType ¶ added in v1.1.0
func (s *SitemapIndex) SetType(t *xml.Attr)
SetType sets the sitemapindex xml namespace type.
type SitemapXML ¶
type SitemapXML struct { ParentNodes []ParentNode `xml:",omitempty"` // contains filtered or unexported fields }
SitemapXML is the top level XML node for the sitemap
func New ¶
func New() *SitemapXML
New returns a new instance of the default XML.
Example ¶
xml := New() out, _ := xml.Output() fmt.Println(string(out))
Output: <?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>
func NewSitemapIndex ¶ added in v1.1.0
func NewSitemapIndex() *SitemapXML
func (*SitemapXML) AddEntry ¶ added in v1.1.1
func (s *SitemapXML) AddEntry(e ChildNode)
AddUrl inserts a URL node into the XML's UrlSet node.
func (*SitemapXML) Output ¶
func (s *SitemapXML) Output() ([]byte, error)
Output returns the output value as bytes
func (*SitemapXML) OutputPrettyString ¶
func (s *SitemapXML) OutputPrettyString(prefix, indent string) (string, error)
OutputPrettyString returns the output as a string with prettified rules. Empty if there's an error.
Example ¶
xml := New() out, _ := xml.OutputPrettyString("", " ") fmt.Println(out)
Output: <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>
func (*SitemapXML) OutputString ¶
func (s *SitemapXML) OutputString() (string, error)
OutputString returns the output as a string. Empty if there's an error.
Example ¶
xml := New() out, _ := xml.OutputString() fmt.Println(out)
Output: <?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>
func (*SitemapXML) PrettyFormat ¶
func (s *SitemapXML) PrettyFormat(prefix, indent string)
Pretty sets the output to use a prettified format.
func (*SitemapXML) SetType ¶
func (s *SitemapXML) SetType(t *xml.Attr)
SetType sets the urlset type and creates a default urlset if necessary.
type Uploader ¶
type Uploader struct { XMLName xml.Name `xml:"video:uploader,omitempty"` // Info (optional) specifies the URL of a webpage with additional information about this uploader. Info string `xml:"info,attr,omitempty"` // Value is the video uploader's name, a string with a maximum of 255 characters. Value string `xml:",chardata"` }
Uploader stores the uploader of the video.
type Url ¶
type Url struct { XMLName xml.Name `xml:"url,omitempty"` Location string `xml:"loc,omitempty"` ChangeFrequency string `xml:"changefreq,omitempty"` Priority string `xml:"priority,omitempty"` LastModifiedDate time.Time `xml:"lastmod,omitempty"` News *News `xml:"news:news,omitempty"` Images []*Image `xml:"image:image,omitempty"` Videos []*Video `xml:"video:video,omitempty"` }
Url is a url block to be nested under UrlSet.
func (*Url) SetLastModified ¶
SetLastModified sets the value of the modified date field.
func (*Url) SetLocation ¶
SetLocation sets the url's location parameter
type UrlSet ¶
type UrlSet struct { XMLName xml.Name `xml:"urlset"` Attributes []*xml.Attr `xml:",attr,omitempty"` Url []ChildNode `xml:"url,omitempty"` }
type Video ¶
type Video struct { XMLName xml.Name `xml:"video:video"` // Title HTML entities must be escaped or wrapped in a CDATA block. Title string `xml:"video:title"` // Description Maximum {{MaxDescriptionLength}} characters. All HTML entities must be escaped or wrapped in a CDATA block. It must match the description displayed on the web page (it doesn't need to be a word-for-word match). Description string `xml:"video:description,omitempty"` ThumbnailLoc string `xml:"video:thumbnail_loc,omitempty"` // ContentLoc HTML and Flash aren't supported formats. ContentLoc string `xml:"video:content_loc,omitempty"` // Can be used instead of or alongside ContentLoc. PlayerLoc string `xml:"video:player_loc,omitempty"` // Duration value must be from {{DurationMin}} to {{DurationMax}} inclusive. Duration int `xml:"video:duration,omitempty"` // ExpirationDate format either YYYY-MM-DD or YYYY-MM-DDThh:mm:ss+TZD ExpirationDate time.Time `xml:"video:expiration_date,omitempty"` // Rating values are float numbers in the range {{RatingLow}} (low) to {{RatingHigh}} (high), inclusive. Rating float32 `xml:"video:rating,omitempty"` ViewCount int `xml:"video:view_count,omitempty"` PublicationDate time.Time `xml:"video:publication_date,omitempty"` // FamilyFriendly whether the video is available with SafeSearch. FamilyFriendly BoolStr `xml:"video:family_friendly,omitempty"` Restrictions []*Restriction `xml:"video:restriction,omitempty"` Platforms []*Platform `xml:"video:platform,omitempty"` // RequiresSubscription indicates whether a subscription is required to view the video. RequiresSubscription BoolStr `xml:"video:requires_subscription,omitempty"` Uploader *Uploader `xml:"video:uploader,omitempty"` // Live indicates whether the video is a live stream Live BoolStr `xml:"video:live,omitempty"` // Tags are limited to a max of {{TagLimit}}. Tags []string `xml:"video:tag,omitempty"` }
Video stores video entry data.
func NewVideo ¶
func NewVideo() *Video
NewVideo returns a new instance of the default Video extension.
func (*Video) AllowCountries ¶
AllowCountries creates a list of allowed countries.
func (*Video) AllowPlatforms ¶
func (v *Video) AllowPlatforms(p ...PlatformName) *Video
AllowPlatforms creates a list of allowed platforms.
func (*Video) DenyCountries ¶
DenyCountries creates a list of denied countries.
func (*Video) DenyPlatforms ¶
func (v *Video) DenyPlatforms(p ...PlatformName) *Video
DenyPlatforms creates a list of denied platforms.
func (*Video) IsFamilyFriendly ¶
IsFamilyFriendly sets the family friendly option to 'yes'
func (*Video) NotFamilyFriendly ¶
NotFamilyFriendly sets the family friendly option to 'no'
func (*Video) SetContentLoc ¶
SetContentLoc sets the video content location parameter.
func (*Video) SetDescription ¶
SetDescription sets the video extensions description parameter.
func (*Video) SetDuration ¶
SetDuration sets the video duration parameter.
func (*Video) SetExpirationDate ¶
SetExpirationDate sets the video ExpirationDate parameter.
func (*Video) SetPlayerLoc ¶
SetPlayerLoc sets the video player location parameter.
func (*Video) SetPublicationDate ¶
SetPublicationDate sets the video extensions PublicationDate parameter.
func (*Video) SetThumbnailLoc ¶
SetThumbnailLoc sets the video thumbnail location parameter.
func (*Video) SetUploader ¶
SetUploader sets the uploader
func (*Video) SetUploaderInfo ¶
SetUploaderInfo sets the uploader
func (*Video) SetUploaderVal ¶
SetUploaderVal sets the uploader value
func (*Video) SetViewCount ¶
SetViewCount sets the video view_count.
func (*Video) SubNotRequired ¶
SubNotRequired sets the requires_subscription option to 'no'
func (*Video) SubRequired ¶
SubRequired sets the requires_subscription option to 'yes'