Skip to content

Instantly share code, notes, and snippets.

@Tranquility
Created January 9, 2014 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tranquility/8336708 to your computer and use it in GitHub Desktop.
Save Tranquility/8336708 to your computer and use it in GitHub Desktop.
Get docker data with go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
func main() {
res, err := http.Get("http://127.0.0.1:4243/images/json")
if err != nil {
log.Fatal(err)
}
result, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal(err)
}
type Image struct {
Id string
}
var images []Image
err = json.Unmarshal(result, &images)
if err != nil {
fmt.Println("error:", err)
}
fmt.Printf("%+v", images)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment