httpc

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 11 Imported by: 0

README

httpc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBody = errors.New("must set []byte, io.Reader, or string for the body")

Functions

This section is empty.

Types

type Client

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

func Must

func Must(base string, opts ...Option) *Client

func New

func New(u *url.URL, opts ...Option) *Client

func (*Client) Do

func (c *Client) Do(ctx context.Context, r Request, v interface{}, customParseFunc func(resp *http.Response, b []byte) error) (err error)

func (*Client) Name

func (c *Client) Name() string

type Error

type Error struct {
	Name    string
	Err     error
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(err error) bool

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Option

type Option func(*Client)

func WithDecode

func WithDecode(d func(data []byte, v interface{}) error) Option

func WithHeaders

func WithHeaders(h ...Value) Option

func WithLogFunc

func WithLogFunc(logFunc func(
	ctx context.Context,
	name string,
	method string,
	url string,
	dur time.Duration,
	statusCode int,
	v any,
	b []byte,
	err error,
),
) Option

func WithName

func WithName(n string) Option

func WithTimeout

func WithTimeout(t time.Duration) Option

func WithTransport

func WithTransport(t http.RoundTripper) Option

type Request

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

func DELETE

func DELETE(handler string, args ...interface{}) Request

func GET

func GET(handler string, args ...interface{}) Request

func NewRequest

func NewRequest(method string) Request

func POST

func POST(handler string, args ...interface{}) Request

func PUT

func PUT(handler string, args ...interface{}) Request

func (Request) Body

func (r Request) Body() (io.Reader, error)

func (Request) HTTP

func (r Request) HTTP(ctx context.Context) (*http.Request, error)

func (Request) Handler

func (r Request) Handler() string

func (Request) Method

func (r Request) Method() string

func (Request) ParseURL

func (r Request) ParseURL() (*url.URL, error)

func (Request) RawBody

func (r Request) RawBody() interface{}

func (Request) URI

func (r Request) URI() string

func (Request) WithBase

func (r Request) WithBase(u *url.URL) Request

func (Request) WithBody

func (r Request) WithBody(
	b interface{},
	encoder func(v interface{}) (io.Reader, error),
	headers ...Value,
) Request

func (Request) WithErrorHandler

func (r Request) WithErrorHandler(h func(statusCode int, b []byte) error) Request

func (Request) WithHeader

func (r Request) WithHeader(value ...Value) Request

func (Request) WithJSONBody

func (r Request) WithJSONBody(b interface{}) Request

func (Request) WithPath

func (r Request) WithPath(path string) Request

func (Request) WithPathf

func (r Request) WithPathf(path string, args ...interface{}) Request

func (Request) WithQuery

func (r Request) WithQuery(value ...Value) Request

type Value

type Value func(values)

func Int

func Int(key string, value int) Value

func Int64

func Int64(key string, value int64) Value

func Intp

func Intp(key string, value *int) Value

func String

func String(key, value string) Value

func Stringp

func Stringp(key string, value *string) Value

func Values

func Values(val map[string][]string) Value

Jump to

Keyboard shortcuts

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