// Adds common parameters to the "params" map, signs the request, // adds the signature to the "params" map and sends the request // to the server. It then unmarshals the response in to the "resp" // parameter using xml.Unmarshal() func (mt *MTurk) query(params map[string]string, operation string, resp interface{}) os.Error { service := MTURK_SERVICE timestamp := time.UTC().Format(TIMESTAMP_FORMAT) params["AWSAccessKeyId"] = mt.Auth.AccessKey params["Service"] = service params["Timestamp"] = timestamp params["Operation"] = operation // make a copy url := *mt.URL sign(mt.Auth, service, operation, timestamp, params) url.RawQuery = multimap(params).Encode() r, err := http.Get(url.String()) if err != nil { return err } dump, _ := http.DumpResponse(r, true) println("DUMP:\n", string(dump)) if r.StatusCode != 200 { return os.NewError(fmt.Sprintf("%d: unexpected status code", r.StatusCode)) } err = xml.Unmarshal(r.Body, resp) r.Body.Close() return err }
func getBuilderList(jsonRoot string) (builders []string) { // Create the URL first url, err := url.Parse(jsonRoot + "/builders") if err != nil { log.Fatal(err) } r, err := http.Get(url.String()) if err != nil { log.Fatal(err) } bodyData, err := ioutil.ReadAll(r.Body) if err != nil { log.Fatal(err) } return parseBuilderList(bodyData) }