forked from ukamnya/microdata_mirror
Fix golint issues and cleanup
parent
7b1ac7f510
commit
2dfc019ddc
22
microdata.go
22
microdata.go
|
@ -18,12 +18,12 @@ import (
|
||||||
"golang.org/x/net/html/atom"
|
"golang.org/x/net/html/atom"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ValueList []interface{}
|
type valueList []interface{}
|
||||||
type PropertyMap map[string]ValueList
|
type propertyMap map[string]valueList
|
||||||
|
|
||||||
// Item represents a microdata item
|
// Item represents a microdata item
|
||||||
type Item struct {
|
type Item struct {
|
||||||
Properties PropertyMap `json:"properties"`
|
Properties propertyMap `json:"properties"`
|
||||||
Types []string `json:"type,omitempty"`
|
Types []string `json:"type,omitempty"`
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ type Item struct {
|
||||||
// NewItem creates a new microdata item
|
// NewItem creates a new microdata item
|
||||||
func NewItem() *Item {
|
func NewItem() *Item {
|
||||||
return &Item{
|
return &Item{
|
||||||
Properties: make(PropertyMap, 0),
|
Properties: make(propertyMap, 0),
|
||||||
Types: make([]string, 0),
|
Types: make([]string, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,11 +132,10 @@ func (p *Parser) Parse() (*Microdata, error) {
|
||||||
}
|
}
|
||||||
// itemid only valid when itemscope and itemtype are both present
|
// itemid only valid when itemscope and itemtype are both present
|
||||||
if itemid, exists := getAttr("itemid", node); exists {
|
if itemid, exists := getAttr("itemid", node); exists {
|
||||||
if parsedUrl, err := p.base.Parse(itemid); err == nil {
|
if parsedURL, err := p.base.Parse(itemid); err == nil {
|
||||||
item.ID = parsedUrl.String()
|
item.ID = parsedURL.String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if itemrefs, exists := getAttr("itemref", node); exists {
|
if itemrefs, exists := getAttr("itemref", node); exists {
|
||||||
|
@ -198,15 +197,14 @@ func (p *Parser) readItem(item *Item, node *html.Node) {
|
||||||
}
|
}
|
||||||
case atom.Audio, atom.Embed, atom.Iframe, atom.Img, atom.Source, atom.Track, atom.Video:
|
case atom.Audio, atom.Embed, atom.Iframe, atom.Img, atom.Source, atom.Track, atom.Video:
|
||||||
if urlValue, exists := getAttr("src", node); exists {
|
if urlValue, exists := getAttr("src", node); exists {
|
||||||
if parsedUrl, err := p.base.Parse(urlValue); err == nil {
|
if parsedURL, err := p.base.Parse(urlValue); err == nil {
|
||||||
propertyValue = parsedUrl.String()
|
propertyValue = parsedURL.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
case atom.A, atom.Area, atom.Link:
|
case atom.A, atom.Area, atom.Link:
|
||||||
if urlValue, exists := getAttr("href", node); exists {
|
if urlValue, exists := getAttr("href", node); exists {
|
||||||
if parsedUrl, err := p.base.Parse(urlValue); err == nil {
|
if parsedURL, err := p.base.Parse(urlValue); err == nil {
|
||||||
propertyValue = parsedUrl.String()
|
propertyValue = parsedURL.String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case atom.Object:
|
case atom.Object:
|
||||||
|
|
Loading…
Reference in New Issue