httpreq

package
v0.0.0-...-553821e Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package httpreq provides general utilities for around net/http requests for a simpler API and extra utilities for parsing JSON request and response boddies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFile

func GetFile(url string, headers map[string]string) (r io.Reader, contentType string, err error)

GetFile is shorthand for http.Get and returns the body as io.Reader as well as occured errors during request execution.

Types

type Response

type Response struct {
	*fasthttp.Response
}

Response extends http.Response with some extra utility functions.

func Get

func Get(url string, headers map[string]string) (*Response, error)

Get is shorthand for Request using the GET method.

func Post

func Post(url string, headers map[string]string, data interface{}) (*Response, error)

Post is shorthand for Request using the POST method.

func Request

func Request(method, url string, headers map[string]string, data interface{}) (res *Response, err error)

Request executes a HTTP request with the given method to the given URL and attaches the passed headers. When data is passed, the object will be serialized using JSON encoder and attached to the request body.

func (*Response) JSON

func (r *Response) JSON(v interface{}) error

JSON parses the response body data to the passed object reference using JSON decoder and returns errors occured.

func (*Response) Release

func (r *Response) Release()

Release releases the request instance back to the request object pool.

func (*Response) ResetState

func (r *Response) ResetState()

Jump to

Keyboard shortcuts

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