Skip to content

Instantly share code, notes, and snippets.

@broccoli1002
Created October 25, 2019 10:44
Show Gist options
  • Save broccoli1002/05843e80ce38c794bdcc198e6c937e47 to your computer and use it in GitHub Desktop.
Save broccoli1002/05843e80ce38c794bdcc198e6c937e47 to your computer and use it in GitHub Desktop.
ResponseCheck
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
const (
tURL = "https://httpbin.org/get"
)
type (
hoge struct {
Foo string `json:"foo"`
fuga `json:"fuga"`
}
fuga struct {
Bar string `json:"bar"`
}
)
func main() {
resp, err := http.Get(tURL)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
ioutil.ReadAll(resp.Body)
h := new(hoge)
if err := json.NewDecoder(resp.Body).Decode(h); err != nil {
var i interface{}
json.NewDecoder(resp.Body).Decode(&i)
log.Printf("%+v", i)
// log.Println(err)
return
}
fmt.Printf("%+v", h)
// if _, err := io.Copy(os.Stdout, resp.Body); err != nil {
// log.Println(err)
// return
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment