webreq

package
v0.0.0-...-e2e6f4c Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHeaders map[string]string
View Source
var ErrInvalidRequest = errors.New("Invalid request")

Functions

func ErrCode

func ErrCode(err error) int

func JSON

func JSON(ctx context.Context, url string, headers map[string]string, req, resp interface{}, limit int64) error

JSON is a JSON-based request/response helper.

func MsgPack

func MsgPack(ctx context.Context, url string, headers map[string]string, req, resp interface{}, limit int64) error

func Raw

func Raw(ctx context.Context, url string, headers map[string]string, limit int64) ([]byte, error)

Types

type HTTPError

type HTTPError struct {
	StatusCode int
	Body       string
}

func (HTTPError) Error

func (he HTTPError) Error() string

type Request

type Request struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, url string) *Request

func (*Request) Body

func (r *Request) Body(raw []byte) *Response

func (*Request) DecodeJSON

func (r *Request) DecodeJSON(v interface{}) error

DecodeJSON is a convenience method for GET requests and calls Response.DecodeJSON directly.

func (*Request) Discard

func (r *Request) Discard() error

func (*Request) Do

func (r *Request) Do() *Response

TODO: this is misleading because "Do" doesn't actually perform the request

func (*Request) File

func (r *Request) File(key, fname string, raw []byte) *Response

func (*Request) Form

func (r *Request) Form(method string, v url.Values) *Response

func (*Request) Header

func (r *Request) Header(key, value string) *Request

func (*Request) Headers

func (r *Request) Headers(h map[string]string) *Request

func (*Request) JSON

func (r *Request) JSON(data interface{}) *Response

func (*Request) Limit

func (r *Request) Limit(l int64) *Request

func (*Request) Method

func (r *Request) Method(m string) *Request

func (*Request) Raw

func (r *Request) Raw() ([]byte, error)

type Response

type Response struct {
	Resp *http.Response
	// contains filtered or unexported fields
}

func (*Response) DecodeJSON

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

func (*Response) Discard

func (r *Response) Discard() error

func (*Response) RC

func (r *Response) RC() (io.ReadCloser, error)

RC returns an unlimited ReadCloser for reading/streaming the response body.

func (*Response) Raw

func (r *Response) Raw() ([]byte, error)

Jump to

Keyboard shortcuts

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