Exemple #1
0
func GetUser(w *rest.ResponseWriter, req *rest.Request) {
	user := User{
		Id:   req.PathParam("id"),
		Name: "Antoine",
	}
	w.WriteJson(&user)
}
Exemple #2
0
func callScenario1(w *rest.ResponseWriter, r *rest.Request) {

	results := callCAndD()

	var returnedResultArray []DataToReturn
	for _, result := range results {
		log.Printf("Returned %s status: %s\n", result.url,
			result.response.Status)
		var jsonBody []byte
		jsonBody, _ = ioutil.ReadAll(result.response.Body)
		log.Println("read all done len=>", len(jsonBody))
		simpleDataFromBody, err2 := simplejson.NewJson(jsonBody)
		log.Println("construction du json")
		if err2 != nil {
			log.Print("err2", err2)
		}
		//var returnedResult map[int]DataToReturn
		//returnedResultArray, err3 := simpleDataFromBody.Get("data").MustArray(returnedResultArray);
		//*if err3 != nil {
		//	log.Print(err3)
		//}
		//		for i, v := range simpleDataFromBody.Get("data").MustArray() {
		//				returnedResult[i], _ = v.(DataToReturn)
		//				log.Println(i, v)
		//		}

		if simpleDataFromBody != nil && simpleDataFromBody.Get("data") == nil {
			//cas ou on a directement un tableau
			log.Println("cas tableau")
			log.Printf("data : %s", simpleDataFromBody)
			elements, err3 := simpleDataFromBody.Array()
			if err3 != nil {
				log.Print(err3)
			}
			log.Println(elements)
		}
		//defer result.response.Body.Close()
	}

	w.WriteJson(returnedResultArray)

	log.Printf("Scenario 1 done")
}