~rogpeppe/goose/state-of-the-world

« back to all changes in this revision

Viewing changes to http/client.go

  • Committer: Ian Booth
  • Date: 2012-11-21 08:46:00 UTC
  • Revision ID: ian.booth@canonical.com-20121121084600-lvg630d6drwziis7
gofmt fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
package http
4
4
 
5
5
import (
 
6
        "bytes"
6
7
        "encoding/json"
7
8
        "errors"
8
9
        "fmt"
 
10
        "io/ioutil"
9
11
        gooseerrors "launchpad.net/goose/errors"
10
 
        "io/ioutil"
11
12
        "net/http"
12
13
        "strings"
13
 
        "bytes"
14
14
)
15
15
 
16
16
type GooseHTTPClient struct {
32
32
}
33
33
 
34
34
type RequestData struct {
35
 
        ReqHeaders http.Header
 
35
        ReqHeaders     http.Header
36
36
        ExpectedStatus []int
37
 
        ReqValue interface{}
38
 
        RespValue interface{}
39
 
        ReqData []byte
40
 
        RespData *[]byte
 
37
        ReqValue       interface{}
 
38
        RespValue      interface{}
 
39
        ReqData        []byte
 
40
        RespData       *[]byte
41
41
}
42
42
 
43
43
// JsonRequest JSON encodes and sends the supplied object (if any) to the specified URL.
50
50
func (c *GooseHTTPClient) JsonRequest(method, url string, reqData *RequestData) (err error) {
51
51
        err = nil
52
52
        var (
53
 
                req      *http.Request
 
53
                req  *http.Request
54
54
                body []byte
55
55
        )
56
56
        if reqData.ReqValue != nil {
166
166
                        }
167
167
                }
168
168
                err = errors.New(
169
 
                fmt.Sprintf(
170
 
                        "request (%s) returned unexpected status: %s; error info: %v; request body: %s",
171
 
                        req.URL,
172
 
                        rawResp.Status,
173
 
                        errInfo,
174
 
                        payloadInfo))
 
169
                        fmt.Sprintf(
 
170
                                "request (%s) returned unexpected status: %s; error info: %v; request body: %s",
 
171
                                req.URL,
 
172
                                rawResp.Status,
 
173
                                errInfo,
 
174
                                payloadInfo))
175
175
                return
176
176
        }
177
177