little more idiomatic code in the example

This commit is contained in:
Martin Angers
2012-09-06 07:55:07 -04:00
parent 5aae70d501
commit e952587198
2 changed files with 3 additions and 5 deletions
+2 -3
View File
@@ -43,7 +43,7 @@ Taken from example_test.go:
)
// This example scrapes the 10 reviews shown on the home page of MetalReview.com,
// the best metal review site on the web :) (no, I'm not affiliated with them)
// the best metal review site on the web :) (and no, I'm not affiliated to them!)
func ExampleScrape_MetalReview() {
// Load the HTML document (in real use, the type would be *goquery.Document)
var doc *Document
@@ -60,8 +60,7 @@ Taken from example_test.go:
// For each item found, get the band, title and score, and print it
band = s.Find("strong").Text()
title = s.Find("em").Text()
score, e := strconv.ParseFloat(s.Find(".score").Text(), 64)
if e != nil {
if score, e = strconv.ParseFloat(s.Find(".score").Text(), 64); e != nil {
// Not a valid float, ignore score
fmt.Printf("Review %d: %s - %s", i, band, title)
} else {
+1 -2
View File
@@ -26,8 +26,7 @@ func ExampleScrape_MetalReview() {
// For each item found, get the band, title and score, and print it
band = s.Find("strong").Text()
title = s.Find("em").Text()
score, e := strconv.ParseFloat(s.Find(".score").Text(), 64)
if e != nil {
if score, e = strconv.ParseFloat(s.Find(".score").Text(), 64); e != nil {
// Not a valid float, ignore score
fmt.Printf("Review %d: %s - %s", i, band, title)
} else {