Created
October 25, 2019 10:44
-
-
Save broccoli1002/05843e80ce38c794bdcc198e6c937e47 to your computer and use it in GitHub Desktop.
ResponseCheck
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" | |
) | |
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