Skip to content

Instantly share code, notes, and snippets.

@kazoo04
Last active August 29, 2015 14: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 kazoo04/edf0348bfc9c411c96fc to your computer and use it in GitHub Desktop.
Save kazoo04/edf0348bfc9c411c96fc to your computer and use it in GitHub Desktop.
Mesiterror API sample
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