Created
January 9, 2014 16:07
-
-
Save Tranquility/8336708 to your computer and use it in GitHub Desktop.
Get docker data with go
This file contains 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 ( | |
"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