request

package
v0.0.0-...-74e38f5 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeJSONUTF8 = "application/json; charset=UTF-8"
	TypeJSON     = "application/json"
)

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)
View Source
var ErrStatusBounds = errors.New("out of bounds http status code")

Functions

func DecodeResponseBody

func DecodeResponseBody(p *Params, response interface{}) error

func Get

func Get(uri string, params map[string][]string, response interface{}) (*http.Response, error)

func Post

func Post(uri string, payload, response interface{}) (*http.Response, error)

func Request

func Request(params *Params, payload interface{}, body interface{}) error

Request makes an http request with params and optional payload to specified Url in params.Url. It will save respond body value into body.

func RequestErr

func RequestErr(p *Params, payload interface{}, body interface{}, e error) (error, bool)

func StatusCodeInBounds

func StatusCodeInBounds(code int) bool

Types

type CustomPayload

type CustomPayload interface {
	io.Reader
	ContentType() string
}

type Error

type Error struct {
	Status  int
	Message interface{}
}

func (*Error) Error

func (e *Error) Error() string

type MultipartBuffer

type MultipartBuffer struct {
	bytes.Buffer
	Boundary string
}

MultipartWriter wraps bytes.Buffer to make it a custom payload.

func (*MultipartBuffer) ContentType

func (w *MultipartBuffer) ContentType() string

type Params

type Params struct {
	ResponseBody string
	Headers      map[string]string
	Cookies      []*http.Cookie
	Method       string
	Password     string
	Request      *http.Request
	Response     *http.Response
	Timeout      time.Duration
	Url          string
	Username     string
}

Jump to

Keyboard shortcuts

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