feather

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2021 License: MIT Imports: 13 Imported by: 1

README

Feather is a golang http client

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = 5 * time.Second
	NoneProxy      = "none"
)

Variables

This section is empty.

Functions

func NewRequestFromOptions

func NewRequestFromOptions(method string, path string, o RequestOptions) (*http.Request, error)

NewRequestFromOptions new http request from RequestOptions

Types

type Client

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

Client is request clinet

var DefaultClient *Client

func NewClient

func NewClient(opts ...Options) *Client

func (*Client) Config

func (c *Client) Config(opt Options) *Client

func (*Client) Delete

func (c *Client) Delete(url string, opts ...RequestOptions) (*PendingRequest, error)

Delete send DELETE http request

func (*Client) Get

func (c *Client) Get(url string, opts ...RequestOptions) (*PendingRequest, error)

Get send GET http request

func (*Client) Interceptor

func (c *Client) Interceptor(pf PipeFunc) *Client

func (*Client) Patch

func (c *Client) Patch(url string, opts ...RequestOptions) (*PendingRequest, error)

Patch send PATCH http request

func (*Client) Post

func (c *Client) Post(url string, opts ...RequestOptions) (*PendingRequest, error)

Post send POST http request

func (*Client) Put

func (c *Client) Put(url string, opts ...RequestOptions) (*PendingRequest, error)

Put send PUT http request

func (*Client) Request

func (c *Client) Request(method, url string, opts ...RequestOptions) (*PendingRequest, error)

Request send http request

type ErrorHandler

type ErrorHandler func(error)

type Handler

type Handler func(r *http.Request) *Result

type Options

type Options struct {
	// BaseURI is prefix of request url
	BaseURI string
	// Timeout request timeout
	Timeout time.Duration
	// ProxyURL set proxy url for request
	ProxyURL string
	// ErrorUnsuccess trigger error if response is not ok
	ErrorUnsuccess bool
}

Options is request client options

type PendingRequest

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

func Delete

func Delete(url string, opts ...RequestOptions) (*PendingRequest, error)

func Get

func Get(url string, opts ...RequestOptions) (*PendingRequest, error)

func Patch

func Patch(url string, opts ...RequestOptions) (*PendingRequest, error)

func Post

func Post(url string, opts ...RequestOptions) (*PendingRequest, error)

func Put

func Put(url string, opts ...RequestOptions) (*PendingRequest, error)

func Request

func Request(method, url string, opts ...RequestOptions) (*PendingRequest, error)

func (*PendingRequest) Catch

func (pr *PendingRequest) Catch(cb ErrorHandler)

func (*PendingRequest) IsSuccess

func (pr *PendingRequest) IsSuccess() bool

func (*PendingRequest) Then

func (pr *PendingRequest) Then(cb interface{}) error

func (*PendingRequest) Wait

func (pr *PendingRequest) Wait() *Result

type PipeFunc

type PipeFunc func(r *http.Request, next Handler) *Result

type Pipeline

type Pipeline []PipeFunc

func (Pipeline) Push

func (pl Pipeline) Push(pf PipeFunc) Pipeline

func (Pipeline) Resolve

func (pl Pipeline) Resolve(r *http.Request, handler Handler) *Result

type RequestOptions

type RequestOptions struct {
	// Body is raw request body
	Body io.Reader
	// Handler is request handler
	Handler Handler
	// Json body of request
	Json interface{}
	// Header is request header
	Header http.Header
	// FormParams is request form params
	FormParams url.Values
	// Query is request query
	Query url.Values
}

RequestOptions simplified http request options

type Result

type Result struct {
	Response *http.Response
	Err      error
	// contains filtered or unexported fields
}

func (*Result) Content

func (r *Result) Content() []byte

func (*Result) ContentString

func (r *Result) ContentString() string

func (*Result) Unmarshal

func (r *Result) Unmarshal(v interface{}) error

type UnsuccessError

type UnsuccessError struct {
	*Result
}

func (UnsuccessError) Error

func (ue UnsuccessError) Error() string

Jump to

Keyboard shortcuts

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