guzzle

package
v1.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HTTPAddrEnvName defines an environment variable name which sets
	// the HTTP address if there is no -http-addr specified.
	HTTPAddrEnvName = "GUZZLE_HTTP_ADDR"

	// HTTPAuthEnvName defines an environment variable name which sets
	// the HTTP authentication header.
	HTTPAuthEnvName = "GUZZLE_HTTP_AUTH"

	// HTTPSSLEnvName defines an environment variable name which sets
	// whether or not to use HTTPS.
	HTTPSSLEnvName = "GUZZLE_HTTP_SSL"
)

Variables

This section is empty.

Functions

func DecodeBody

func DecodeBody(resp *http.Response, out interface{}) error

decodeBody is used to JSON decode a body

func DefaultPooledTransport

func DefaultPooledTransport() *http.Transport

DefaultPooledTransport returns a new http.Transport with similar default values to http.DefaultTransport. Do not use this for transient transports as it can leak file descriptors over time. Only use this for transports that will be re-used for the same host(s).

func NewHttpClient

func NewHttpClient(transport *http.Transport, tlsConf TLSConfig) (*http.Client, error)

NewHttpClient returns an http client configured with the given Transport and TLS config.

func SetupTLSConfig

func SetupTLSConfig(tlsConfig *TLSConfig) (*tls.Config, error)

func TextDecodeBody

func TextDecodeBody(resp *http.Response, out string) error

func ValidateHostConn

func ValidateHostConn(config *Config) error

func XmlDecodeBody

func XmlDecodeBody(resp *http.Response, out interface{}) error

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient returns a new client

func (*Client) DoNewRequest

func (c *Client) DoNewRequest(method, path string) *request

DoNewRequest new a request is used to create a request struct

func (*Client) NewDoRequest

func (c *Client) NewDoRequest(r *request) (time.Duration, *http.Response, error)

NewDoRequest runs a request instance with http client

func (*Client) SetBaseAuth added in v1.0.4

func (c *Client) SetBaseAuth(username, password string) *Client

func (*Client) SetTransport added in v1.0.4

func (c *Client) SetTransport(transportFn func() *http.Transport) *Client

func (*Client) SetValidateHost added in v1.0.4

func (c *Client) SetValidateHost(v bool) *Client

type Config

type Config struct {
	// Address is the address of the Guzzle core
	Address string

	// Scheme is the URI scheme for the Guzzle core
	Scheme string

	// Transport is the Transport to use for the http client.
	Transport *http.Transport

	// HttpClient is the client to use. Default will be
	// used if not provided.
	HttpClient *http.Client

	// HttpAuth is the auth info to use for http access.
	HttpAuth *HttpBasicAuth

	// WaitTime limits how long a Watch will block. If not provided,
	// the agent default values will be used.
	WaitTime time.Duration

	TLSConfig TLSConfig

	ValidateHost bool
}

Config is used to configure the creation of a client

func DefaultConfig

func DefaultConfig() *Config

type HttpBasicAuth

type HttpBasicAuth struct {
	// Username to use for HTTP Basic Authentication
	Username string

	// Password to use for HTTP Basic Authentication
	Password string
}

HttpBasicAuth is used to authenticate http client with HTTP Basic Authentication

type Response

type Response struct {
	Duration time.Duration

	// StatusCode is the HTTP Status Code returned by the HTTP Response. Taken from resp.StatusCode.
	StatusCode int

	// Header stores the response headers as http.Header interface.
	Header http.Header

	// Cookies stores the parsed response cookies.
	Cookies []*http.Cookie

	// Expose the native Go http.Response object for convenience.
	RawResponse *http.Response

	// Expose original request Context for convenience.
	Context *context.Context

	Err error
}

func RequireOK

func RequireOK(d time.Duration, resp *http.Response, e error) *Response

RequireOK is used to wrap doRequest

func (*Response) Close

func (resp *Response) Close()

func (*Response) Json

func (resp *Response) Json(useStruct interface{}) error

func (*Response) Xml

func (resp *Response) Xml(useStruct interface{}) error

type TLSConfig

type TLSConfig struct {
	// Address is the optional address of the Guzzle core. The port, if any
	// will be removed from here and this will be set to the ServerName of the
	// resulting config.
	Address string

	// CAFile is the optional path to the CA certificate used for Guzzle
	// communication, defaults to the system bundle if not specified.
	CAFile string

	// CAPath is the optional path to a directory of CA certificates to use for
	// Guzzle communication, defaults to the system bundle if not specified.
	CAPath string

	// CertFile is the optional path to the certificate for Guzzle
	// communication. If this is set then you need to also set KeyFile.
	CertFile string

	// KeyFile is the optional path to the private key for Guzzle communication.
	// If this is set then you need to also set CertFile.
	KeyFile string

	// InsecureSkipVerify if set to true will disable TLS host verification.
	InsecureSkipVerify bool
}

TLSConfig is used to generate a TLSClientConfig that's useful for talking to Guzzle using TLS.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL