type Doer interface { Do(req *http.Request) (*http.Response, error) }
Doer executes http requests. It is implemented by *http.Client. You can wrap *http.Client with layers of Doers to form a stack of client-side middleware.
type Sling struct {
// contains filtered or unexported fields
}
Sling is an HTTP Request builder and sender.
func New() *Sling
New returns a new Sling with an http DefaultClient.
func (s *Sling) Add(key, value string) *Sling
Add adds the key, value pair in Headers, appending values for existing keys to the key's values. Header keys are canonicalized.
func (s *Sling) Base(rawURL string) *Sling
Base sets the rawURL. If you intend to extend the url with Path, baseUrl should be specified with a trailing slash.
func (s *Sling) Body(body io.Reader) *Sling
Body sets the Sling's body. The body value will be set as the Body on new requests (see Request()). If the provided body is also an io.Closer, the request Body will be closed by http.Client methods.
func (s *Sling) BodyForm(bodyForm interface{}) *Sling
BodyForm sets the Sling's bodyForm. The value pointed to by the bodyForm will be url encoded as the Body on new requests (see Request()). The bodyStruct argument should be a pointer to a url tagged struct. See https://godoc.org/github.com/google/go-querystring/query for details.
func (s *Sling) BodyJSON(bodyJSON interface{}) *Sling
BodyJSON sets the Sling's bodyJSON. The value pointed to by the bodyJSON will be JSON encoded as the Body on new requests (see Request()). The bodyJSON argument should be a pointer to a JSON tagged struct. See https://golang.org/pkg/encoding/json/#MarshalIndent for details.
func (s *Sling) Client(httpClient *http.Client) *Sling
Client sets the http Client used to do requests. If a nil client is given, the http.DefaultClient will be used.
func (s *Sling) Delete(pathURL string) *Sling
Delete sets the Sling method to DELETE and sets the given pathURL.
func (s *Sling) Do(req *http.Request, successV, failureV interface{}) (*http.Response, error)
Do sends an HTTP request and returns the response. Success responses (2XX) are JSON decoded into the value pointed to by successV and other responses are JSON decoded into the value pointed to by failureV. Any error sending the request or decoding the response is returned.
func (s *Sling) Doer(doer Doer) *Sling
Doer sets the custom Doer implementation used to do requests. If a nil client is given, the http.DefaultClient will be used.
func (s *Sling) Get(pathURL string) *Sling
Get sets the Sling method to GET and sets the given pathURL.
func (s *Sling) Head(pathURL string) *Sling
Head sets the Sling method to HEAD and sets the given pathURL.
func (s *Sling) New() *Sling
New returns a copy of a Sling for creating a new Sling with properties from a parent Sling. For example,
parentSling := sling.New().Client(client).Base("https://api.io/") fooSling := parentSling.New().Get("foo/") barSling := parentSling.New().Get("bar/")
fooSling and barSling will both use the same client, but send requests to https://api.io/foo/ and https://api.io/bar/ respectively.
Note that query and body values are copied so if pointer values are used, mutating the original value will mutate the value within the child Sling.
func (s *Sling) Patch(pathURL string) *Sling
Patch sets the Sling method to PATCH and sets the given pathURL.
func (s *Sling) Path(path string) *Sling
Path extends the rawURL with the given path by resolving the reference to an absolute URL. If parsing errors occur, the rawURL is left unmodified.
func (s *Sling) Post(pathURL string) *Sling
Post sets the Sling method to POST and sets the given pathURL.
func (s *Sling) Put(pathURL string) *Sling
Put sets the Sling method to PUT and sets the given pathURL.
func (s *Sling) QueryStruct(queryStruct interface{}) *Sling
QueryStruct appends the queryStruct to the Sling's queryStructs. The value pointed to by each queryStruct will be encoded as url query parameters on new requests (see Request()). The queryStruct argument should be a pointer to a url tagged struct. See https://godoc.org/github.com/google/go-querystring/query for details.
func (s *Sling) Receive(successV, failureV interface{}) (*http.Response, error)
Receive creates a new HTTP request and returns the response. Success responses (2XX) are JSON decoded into the value pointed to by successV and other responses are JSON decoded into the value pointed to by failureV. Any error creating the request, sending it, or decoding the response is returned. Receive is shorthand for calling Request and Do.
func (s *Sling) ReceiveSuccess(successV interface{}) (*http.Response, error)
ReceiveSuccess creates a new HTTP request and returns the response. Success responses (2XX) are JSON decoded into the value pointed to by successV. Any error creating the request, sending it, or decoding a 2XX response is returned.
func (s *Sling) Request() (*http.Request, error)
Request returns a new http.Request created with the Sling properties. Returns any errors parsing the rawURL, encoding query structs, encoding the body, or creating the http.Request.
func (s *Sling) Set(key, value string) *Sling
Set sets the key, value pair in Headers, replacing existing values associated with key. Header keys are canonicalized.
func (s *Sling) SetBasicAuth(username, password string) *Sling
SetBasicAuth sets the Authorization header to use HTTP Basic Authentication with the provided username and password. With HTTP Basic Authentication the provided username and password are not encrypted.