Back to

Package please

Latest Go to latest

The highest tagged major version is .

Published: Feb 13, 2020 | License: NCSA | Module:



const DefaultUserAgent = "please/0.1 (ask nicely;"

DefaultUserAgent with which to identify.

const MaxRetentionSize = 1024 * 50

MaxRetentionSize for responses. Mostly used by clientResponse.JSON. If the response body is less than this, it will be replaced with a bytes.Buffer containing the responseif client.Response.ReadAll() and client.Response.JSON() are used. Obviously, directly accessing the response body will nullify any benefit from this.


var ErrClientInitialization = errors.NewError("error initializing client")

ErrClientInitialization is raised by TLS-enabled clients whenever the assigned server certificate cannot be loaded or parsed.

var ErrClientRequest = errors.NewError("error in client with request setup or completion")

ErrClientRequest is raised whenever an error occurs during a client request.

var ErrEncoding = errors.NewError("error encoding data")

ErrEncoding is returned whenever an error occurs while encoding data, be it JSON or otherwise.

var ErrParsingURL = errors.NewError("error parsing URL")

ErrParsingURL is returned by the HTTP client if a given URL cannot be parsed.

type ClientRequest

type ClientRequest struct {
	Method  string
	Request *http.Request
	URL     string
	Path    string
	Host    string
	// contains filtered or unexported fields

func (*ClientRequest) Body

func (req *ClientRequest) Body(reader io.Reader) *ClientRequest

func (*ClientRequest) Commit

func (req *ClientRequest) Commit() (*clientResponse, error)

func (*ClientRequest) Each

func (req *ClientRequest) Each(fn codeHandler) *ClientRequest

func (*ClientRequest) Form

func (req *ClientRequest) Form() *url.Values

func (*ClientRequest) Headers

func (req *ClientRequest) Headers() *http.Header

func (*ClientRequest) On

func (req *ClientRequest) On(code int, fn codeHandler) *ClientRequest

On assigns a function to call when a status code of a specific value is encountered.

func (*ClientRequest) Query

func (req *ClientRequest) Query() *url.Values

func (*ClientRequest) WriteJSON

func (req *ClientRequest) WriteJSON(v interface{}) error

type Requester

type Requester struct {
	BaseURL        string
	BasePath       string
	Headers        http.Header
	SessionCookies *cookiejar.Jar
	// contains filtered or unexported fields

func MakeRequest

func MakeRequest(baseURL string) *Requester

func WithCertificate

func WithCertificate(request *Requester, certPath string) (*Requester, error)

func WithTLS

func WithTLS(request *Requester) *Requester

func WithUnverifiedTLS

func WithUnverifiedTLS(request *Requester) *Requester

func (*Requester) ChangeUserAgent

func (c *Requester) ChangeUserAgent(ua string) *Requester

func (*Requester) Client

func (c *Requester) Client() *http.Client

Client returns the http.Client associated with this Requester.

func (*Requester) Delete

func (c *Requester) Delete(path string) *ClientRequest

func (*Requester) Each

func (c *Requester) Each(fn codeHandler) *Requester

Each applies the specified function to all requests with any status code.

func (*Requester) Get

func (c *Requester) Get(path string) *ClientRequest

func (*Requester) Head

func (c *Requester) Head(path string) *ClientRequest

func (*Requester) Method

func (c *Requester) Method(method, path string) *ClientRequest

func (*Requester) On

func (c *Requester) On(code int, fn codeHandler) *Requester

On assigns a function to call when a status code of a specific value is encountered. This is the global variant of it that applies to all requests.

func (*Requester) Patch

func (c *Requester) Patch(path string) *ClientRequest

func (*Requester) Post

func (c *Requester) Post(path string) *ClientRequest

func (*Requester) Put

func (c *Requester) Put(path string) *ClientRequest

func (*Requester) SetClient

func (c *Requester) SetClient(client *http.Client)

SetClient replaces the internal pre-configured stdlib client with the specified client implementation. This is mostly useful for unit tests.

Package Files

  • errors.go
  • request.go
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier