ch5-10 fmt code

This commit is contained in:
D 2016-01-11 23:44:13 +08:00
parent 5c288d0893
commit 45b04fc567

View File

@ -35,15 +35,15 @@ deferred函數幫助Parse從panic中恢複。在deferred函數內部panic val
func soleTitle(doc *html.Node) (title string, err error) { func soleTitle(doc *html.Node) (title string, err error) {
type bailout struct{} type bailout struct{}
defer func() { defer func() {
switch p := recover(); p { switch p := recover(); p {
case nil: case nil:
// no panic // no panic
case bailout{}: case bailout{}:
// "expected" panic // "expected" panic
err = fmt.Errorf("multiple title elements") err = fmt.Errorf("multiple title elements")
default: default:
panic(p) // unexpected panic; carry on panicking panic(p) // unexpected panic; carry on panicking
} }
}() }()
// 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) {