I'm posting the following json string:
{'foods':[{'vName':'bean','color':'green','size':'small'},
{'vName':'carrot','color':'orange', 'size':'medium'}]}
I'm posting to Go using Restangular, and the receiving func is:
func CreateFoods(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
var food Food //this needs to be an array or something?
dec := json.NewDecoder(r.Body)
dec.Decode(&food)
}
My Food struct:
type Food struct{
VName string `json:"vName"`
Color string `json:"color"`
Size string `json:"size"`
}
I've used this routine for cases where where I post a single entity, but now I want to post multiple entities, and I cannot figure out how to map this json example to multiple entities. Also, I'm trying to "see" the JSON POST, to see the JSON string, then if I have to, I can work with the string to make the entities. I cannot figure out how to get a hold of the JSON string from http.Request.