February 2019
Intermediate to advanced
450 pages
11h 59m
English
To explore how to work with remote data from a web service, we shall start by adapting our web service example from Chapter 3, Go to the Rescue!. The code is slimmed down and updated to use the same readStream() function as created for the preceding image example. The resulting code is very basic but demonstrates how easily we can decode JSON data into a struct using built-in Go features:
type Person struct { Title string `json:"title,omitempty"` Firstname string `json:"firstname"` Surname string `json:"surname"` Username string `json:"username"` Password string `json:"-"`}func main() { fmt.Println("Downloading...") stream := remote.ReadStream("http://echo.jsontest.com/title/Sir/" + "firstname/Tom/surname/Jones/username/singer1/")
Read now
Unlock full access