Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple client that HTTP gets and JSON parses an endpoint
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
You can’t perform that action at this time.