mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2024-12-26 06:46:27 +00:00
ch5-10: fmt code
This commit is contained in:
parent
d7c078a7f2
commit
1c0ac14e5e
@ -47,17 +47,18 @@ func soleTitle(doc *html.Node) (title string, err error) {
|
|||||||
}()
|
}()
|
||||||
// Bail out of recursion if we find more than one nonempty title.
|
// Bail out of recursion if we find more than one nonempty title.
|
||||||
forEachNode(doc, func(n *html.Node) {
|
forEachNode(doc, func(n *html.Node) {
|
||||||
if n.Type == html.ElementNode && n.Data == "title" && n.FirstChild != nil {
|
if n.Type == html.ElementNode && n.Data == "title" &&
|
||||||
if title != "" {
|
n.FirstChild != nil {
|
||||||
panic(bailout{}) // multiple titleelements
|
if title != "" {
|
||||||
|
panic(bailout{}) // multiple titleelements
|
||||||
|
}
|
||||||
|
title = n.FirstChild.Data
|
||||||
}
|
}
|
||||||
title = n.FirstChild.Data
|
|
||||||
}
|
|
||||||
}, nil)
|
}, nil)
|
||||||
if title == "" {
|
if title == "" {
|
||||||
return "", fmt.Errorf("no title element")
|
return "", fmt.Errorf("no title element")
|
||||||
}
|
}
|
||||||
return title, nil
|
return title, nil
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user