Last active
August 29, 2015 14:07
-
-
Save kazoo04/edf0348bfc9c411c96fc to your computer and use it in GitHub Desktop.
Mesiterror API sample
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 ( | |
"net/http" | |
"net/url" | |
"io/ioutil" | |
"encoding/json" | |
"fmt" | |
) | |
type Result struct { | |
Url string | |
Label bool | |
Score float64 | |
Error string | |
} | |
func main() { | |
resp, _ := http.PostForm( | |
"http://food.kazoo04.com:8080/api/v0/upload", | |
url.Values{"url": {"http://www.example.com/image.jpg"} }, | |
) | |
body, _ := ioutil.ReadAll(resp.Body) | |
defer resp.Body.Close() | |
response := string(body) | |
var data []Result | |
err := json.Unmarshal([]byte(response), &data) | |
if err == nil { | |
fmt.Printf("%+v\n", data) | |
fmt.Println("url = ", data[0].Url) | |
fmt.Println("label = ", data[0].Label) | |
fmt.Println("error = ", data[0].Error) | |
} else { | |
fmt.Println("error") | |
fmt.Println(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment