fix: coding style and file format for chapter 11, 12, 13, 14 and 15.

This commit is contained in:
Bo-Yi Wu
2017-02-11 12:32:16 +08:00
parent c5413075c1
commit 4abbfabb52
63 changed files with 2662 additions and 2622 deletions

View File

@@ -1,33 +1,34 @@
// twitter_status_json.go
package main
import (
"net/http"
"fmt"
"encoding/json"
"io/ioutil"
)
type Status struct {
Text string
}
type User struct {
Status Status
}
func main() {
/* perform an HTTP request for the twitter status of user: Googland */
res, _:= http.Get("http://twitter.com/users/Googland.json")
/* initialize the structure of the JSON response */
user := User{Status{""}}
/* unmarshal the JSON into our structures */
temp, _ := ioutil.ReadAll(res.Body)
body := []byte(temp)
json.Unmarshal(body, &user)
fmt.Printf("status: %s", user.Status.Text)
}
/* Output:
status: Robot cars invade California, on orders from Google:
Google has been testing self-driving cars ... http://bit.ly/cbtpUN http://retwt.me/97p
*/
// twitter_status_json.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Status struct {
Text string
}
type User struct {
Status Status
}
func main() {
/* perform an HTTP request for the twitter status of user: Googland */
res, _ := http.Get("http://twitter.com/users/Googland.json")
/* initialize the structure of the JSON response */
user := User{Status{""}}
/* unmarshal the JSON into our structures */
temp, _ := ioutil.ReadAll(res.Body)
body := []byte(temp)
json.Unmarshal(body, &user)
fmt.Printf("status: %s", user.Status.Text)
}
/* Output:
status: Robot cars invade California, on orders from Google:
Google has been testing self-driving cars ... http://bit.ly/cbtpUN http://retwt.me/97p
*/