libhttp

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Do(req *http.Request, dst ...interface{}) error
	Get(url string, dst ...interface{}) error
	PostForm(url string, data map[string][]string, dst ...interface{}) error
}

Client expl

type ClientHolder

type ClientHolder struct {
	HTTP *http.Client
}

ClientHolder is a holder for an ordinary http.Client, with additional functionality.

func NewClient

func NewClient(certificates ...string) (*ClientHolder, error)

NewClient sets up a new libhttp.Client. The client has http.Client's default values with the following exceptions: HTTP2 is forced; TLS12 or greater; additional RootCAs from provided files and from predefined authorities. Takes none or more optional files to add as certificates to the client.

func (ClientHolder) Do

func (client ClientHolder) Do(req *http.Request, dst ...interface{}) error

Do is a wrapper around http.do that error checks and decodes the response to the (optional) destination. 'dst' is an optional destination pointer that must be either implementing io.writer or a struct to be populated by JSON data. As 'dst' is a variadic argument, multiple 'dst' may be passed. However; any additional destinations are ignored with no error.

func (ClientHolder) Get

func (client ClientHolder) Get(url string, dst ...interface{}) error

Get is a simplified way to do a HTTP GET request by just having a url and (optionally) a destination for the response. 'dst' is an optional destination pointer that must be either implementing io.writer or a struct to be populated by JSON data. As 'dst' is a variadic argument, multiple 'dst' may be passed. However; any additional destinations are ignored with no error.

func (ClientHolder) PostForm

func (client ClientHolder) PostForm(url string, data map[string][]string, dst ...interface{}) error

PostForm is a wrapper around http.PostForm that takes a map as input, and makes error checks and decodes the response to the (optional) destination. 'dst' is an optional destination pointer that must be either implementing io.writer or a struct to be populated by JSON data. As 'dst' is a variadic argument, multiple 'dst' may be passed. However; any additional destinations are ignored with no error.

Jump to

Keyboard shortcuts

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