Documentation ¶
Overview ¶
Package http provides an easy way to construct an http client with custom certificates and customizable timeout. If you need to customize other attributes you can use the golang http package. https://golang.org/pkg/net/http/
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidTransportType defines the error to be returned if the transport defined for the client is incorrect ErrInvalidTransportType = errors.New("roundTripper transport invalid, should be http type") // ErrEmptyArg defines the error to be returned if an option is defined with an empty argument ErrEmptyArg = errors.New("argument is empty") )
Functions ¶
func New ¶
func New(opts ...ClientOption) (*http.Client, error)
New creates a new http.Client with the Passed Client Options that will have a custom certificate if it is loaded from the passed CA Bundle file and/or directory. If both CABundleFile and CABundleDir are empty arguments, it creates an unsecure HTTP client.
Types ¶
type ClientOption ¶
ClientOption defines the format of the client option functions Note that many options defined in this package rely on the Transport for the http.Client being of type *http.Transport. Using a different Transport will cause these options to fail.
func WithAcceptInvalidHostname ¶
func WithAcceptInvalidHostname(acceptInvalidHostname string) ClientOption
WithAcceptInvalidHostname allows the client to call the acceptInvalidHostname host instead of the host from the certificates.
func WithCABundleDir ¶
func WithCABundleDir(CABundleDir string) ClientOption
WithCABundleDir adds the CABundleDir looks for pem certs in the CABundleDir and adds them to the the client's certPool.
func WithCABundleFile ¶
func WithCABundleFile(CABundleFile string) ClientOption
WithCABundleFile adds the CABundleFile cert to the the client's certPool
func WithTLSInsecureSkipVerify ¶
func WithTLSInsecureSkipVerify() ClientOption
WithTLSInsecureSkipVerify allows the client to call any host without checking the certificates.
func WithTimeout ¶
func WithTimeout(httpTimeout time.Duration) ClientOption
WithTimeout sets the timeout for the client, if not called the timeout will be 0 (no timeout).