Created
September 3, 2018 11:09
-
-
Save janithl/d3513971b168e4569d0845433f16633c to your computer and use it in GitHub Desktop.
Simple client that HTTP gets and JSON parses an endpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "net/http" | |
import "fmt" | |
import "io/ioutil" | |
import "encoding/json" | |
// Artist is a struct to hold artist values | |
type Artist struct { | |
Name, Shortname, Reknown, Bio string | |
} | |
func main() { | |
resp, err := http.Get("https://gist.githubusercontent.com/planetoftheweb/98f35786733c8cccf81e/raw/f3dad774ed1fe20b36011b1261bb392ee759b867/data.json") | |
if err != nil { | |
panic(err) | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
panic(err) | |
} | |
artists := make([]Artist, 1) | |
if err := json.Unmarshal(body, &artists); err != nil { | |
panic(err) | |
} | |
for _, artist := range artists { | |
fmt.Printf("%s (%s)\n%s\n\n", artist.Name, artist.Shortname, artist.Reknown) | |
fmt.Println(artist.Bio + "\n\n") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment