mirror of
https://github.com/avelino/awesome-go.git
synced 2024-11-07 16:33:40 +00:00
handle error in extractCategories
This commit is contained in:
parent
44ea02d965
commit
270d554b95
27
main.go
27
main.go
@ -175,7 +175,6 @@ func renderCategories(categories map[string]Category) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func renderSitemap(categories map[string]Category) error {
|
func renderSitemap(categories map[string]Category) error {
|
||||||
// FIXME: handle error
|
|
||||||
f, err := os.Create(outSitemapFile)
|
f, err := os.Create(outSitemapFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("create sitemap file `%s`: %w", outSitemapFile, err)
|
return fmt.Errorf("create sitemap file `%s`: %w", outSitemapFile, err)
|
||||||
@ -192,29 +191,43 @@ func renderSitemap(categories map[string]Category) error {
|
|||||||
|
|
||||||
func extractCategories(doc *goquery.Document) (map[string]Category, error) {
|
func extractCategories(doc *goquery.Document) (map[string]Category, error) {
|
||||||
categories := make(map[string]Category)
|
categories := make(map[string]Category)
|
||||||
|
var rootErr error
|
||||||
|
|
||||||
doc.
|
doc.
|
||||||
Find("body #contents").
|
Find("body #contents").
|
||||||
NextFiltered("ul").
|
NextFiltered("ul").
|
||||||
Find("ul").
|
Find("ul").
|
||||||
Each(func(_ int, selUl *goquery.Selection) {
|
EachWithBreak(func(_ int, selUl *goquery.Selection) bool {
|
||||||
|
if rootErr != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
selUl.
|
selUl.
|
||||||
Find("li a").
|
Find("li a").
|
||||||
Each(func(_ int, s *goquery.Selection) {
|
EachWithBreak(func(_ int, s *goquery.Selection) bool {
|
||||||
selector, exists := s.Attr("href")
|
selector, exists := s.Attr("href")
|
||||||
if !exists {
|
if !exists {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
category, err := extractCategory(doc, selector)
|
category, err := extractCategory(doc, selector)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
rootErr = fmt.Errorf("extract category: %w", err)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
categories[selector] = *category
|
categories[selector] = *category
|
||||||
})
|
|
||||||
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
// FIXME: handle error
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
if rootErr != nil {
|
||||||
|
return nil, fmt.Errorf("extract categories: %w", rootErr)
|
||||||
|
}
|
||||||
|
|
||||||
return categories, nil
|
return categories, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user