예제 #1
0
func (c Client) GetRequest(url string, ref interface{}) *objects.CodedError {
	if len(url) == 0 {
		return objects.NewError("Could not GET: no URL specified", 500)
	}
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return objects.FromError(err, 500)
	}
	req.Header.Set(PTV_HDR, PTV_HDR_VAL)

	resp, err := c.Do(req)
	if err != nil {
		return objects.FromError(err, 500)
	}
	status := resp.StatusCode
	log.Printf("GET received status code of %d", status)
	if status == 200 {
		buffer, err2 := c.ReadBody(resp)
		log.Printf("GET received body %s", buffer)
		defer resp.Body.Close()
		if err2 != nil {
			return objects.FromError(err2, 500)
		}
		log.Printf("GET response body read, len=%d", len(buffer))
		err2 = objects.Unmarshal(ref, buffer)
		if err2 != nil {
			return objects.FromError(err2, 500)
		}
		return nil
	}
	return objects.NewErrorf("Unsuccessful request, server returned %d", status, status)
}
예제 #2
0
func (r InventoryRequestProcessor) Unmarshal(buffer []byte) (objects.Storable, error) {
	obj := objects.AvailabilityRequestObject{}
	log.Printf("InventoryAPIProcessor unmarshalling with empty object of type %T", obj)
	err := objects.Unmarshal(&obj, buffer)
	return obj, err
}
예제 #3
0
func (r OrderAPIProcessor) Unmarshal(buffer []byte) (objects.Storable, error) {
	obj := objects.OrderObject{}
	err := objects.Unmarshal(&obj, buffer)
	return obj, err
}