hc stands for "http client". It is built on top of fasthttp and provides some handy shortcuts to http client methods.
const (
MethodGet = "GET"
MethodPost = "POST"
MethodPut = "PUT"
MethodDelete = "DELETE"
DefaultReadTimeout = time.Duration(0)
DefaultWriteTimeout = time.Duration(0)
)
func Delete(url string, body []byte, headers Headers) (int, []byte, error)
Delete makes a DELETE request to url, sends body in request body, sends headers and returns http status code, response body, error
func Get(url string) (int, []byte, error)
Get makes a GET request to url and returns: http status code, response body, error
func MakeRawRequest(req *Request, res *Response) error
MakeRequest is doing a request using req and res and returns an error
func Post(url string, body []byte, headers Headers) (int, []byte, error)
Post makes a POST request to url, sends body in request body, sends headers and returns http status code, response body, error
func Put(url string, body []byte, headers Headers) (int, []byte, error)
Put makes a PUT request to url, sends body in request body, sends headers and returns http status code, response body, error
func SetReadTimeout(t time.Duration)
SetReadTimeout sets the client ReadTimeout
func SetWriteTimeout(t time.Duration)
SetWriteTimeout sets the client WriteTimeout
type Headers map[string]string
Headers key/value map if headers
func (h Headers) Add(k string, v string)
Add adds a header to Headers
type Request struct {
*fasthttp.Request
}
Request request object
func AcquireRequest() *Request
AcquireRequest returns a new Request
func (r *Request) WriteJSON(v interface{}) error
WriteJSON will write v (as json) to Request body
type Response struct {
*fasthttp.Response
}
Response response object
func AcquireResponse() *Response
AcquireResponse returns a new response
func MakeRequest(method string, url string, body []byte, headers Headers) (*Response, error)
MakeRequest makes a new request using method to url, sends body in post body, sends headers in headers and returns Response object and/or error
func (r *Response) ReadJSON(v interface{}) error
ReadJSON will read json into v from Response body