I came across a weird problem. Please see the code below:
var p Person
data, _ := ioutil.ReadAll(r.Body) //data will not be empty
json.NewDecoder(r.Body).Decode(&p) //it will be empty upon reading
fmt.Println(p.ID) //will be empty
json.NewDecoder(r.Body).Decode(&p) //will not be empty
body, _ := ioutil.ReadAll(r.Body) //it will be empty upon reading
fmt.Println(p.ID) //will not be empty
As you can see from the code, if I read the r.Body first, then check it, it is empty. Why does it become empty after reading from the IO stream?