httputil

package
v0.0.0-...-d31700d Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = &Client{Client: &http.Client{Timeout: 10 * time.Second}}

Functions

func DeleteJson

func DeleteJson(url string, headers map[string]string, body, data interface{}) error

func DeleteJsonCtx

func DeleteJsonCtx(ctx context.Context, opName, url string, headers map[string]string, body, data interface{}) error

func GetJson

func GetJson(url string, headers map[string]string, body, data interface{}) error

func GetJsonCtx

func GetJsonCtx(ctx context.Context, opName, url string, headers map[string]string, body, data interface{}) error

func HeadJson

func HeadJson(url string, headers map[string]string, body, data interface{}) error

func HeadJsonCtx

func HeadJsonCtx(ctx context.Context, opName, url string, headers map[string]string, body, data interface{}) error

func PostJson

func PostJson(url string, headers map[string]string, body, data interface{}) error

func PostJsonCtx

func PostJsonCtx(ctx context.Context, opName, url string, headers map[string]string, body, data interface{}) error

func PutJson

func PutJson(url string, headers map[string]string, body, data interface{}) error

func PutJsonCtx

func PutJsonCtx(ctx context.Context, opName, url string, headers map[string]string, body, data interface{}) error

Types

type Client

type Client struct {
	BaseUrl       string
	Client        *http.Client
	MarshalFunc   func(v interface{}) ([]byte, error)
	UnmarshalFunc func(data []byte, v interface{}) error
}

func (*Client) Delete

func (c *Client) Delete(url string, headers map[string]string, body interface{}) (*Response, error)

func (*Client) DeleteCtx

func (c *Client) DeleteCtx(
	ctx context.Context, opName, url string, headers map[string]string, body interface{},
) (*Response, error)

func (*Client) DeleteJson

func (c *Client) DeleteJson(url string, headers map[string]string, body, data interface{}) error

func (*Client) DeleteJsonCtx

func (c *Client) DeleteJsonCtx(ctx context.Context, opName, url string, headers map[string]string, body, data interface{}) error

func (*Client) Do

func (c *Client) Do(method, url string, headers map[string]string, body interface{}) (*Response, error)

func (*Client) DoCtx

func (c *Client) DoCtx(
	ctx context.Context, opName, method, url string, headers map[string]string, body interface{},
) (*Response, error)

func (*Client) DoJson

func (c *Client) DoJson(method, url string, headers map[string]string, body, data interface{}) error

func (*Client) DoJsonCtx

func (c *Client) DoJsonCtx(
	ctx context.Context, opName, method, url string, headers map[string]string, body, data interface{},
) error

func (*Client) DoReq

func (c *Client) DoReq(req *http.Request) (*Response, error)

func (*Client) Get

func (c *Client) Get(url string, headers map[string]string, body interface{}) (*Response, error)

func (*Client) GetCtx

func (c *Client) GetCtx(
	ctx context.Context, opName, url string, headers map[string]string, body interface{},
) (*Response, error)

func (*Client) GetJson

func (c *Client) GetJson(url string, headers map[string]string, body, data interface{}) error

func (*Client) GetJsonCtx

func (c *Client) GetJsonCtx(ctx context.Context, opName, url string, headers map[string]string, body, data interface{}) error

func (*Client) GetMarshalFunc

func (c *Client) GetMarshalFunc() func(v interface{}) ([]byte, error)

func (*Client) Head

func (c *Client) Head(url string, headers map[string]string, body interface{}) (*Response, error)

func (*Client) HeadCtx

func (c *Client) HeadCtx(
	ctx context.Context, opName, url string, headers map[string]string, body interface{},
) (*Response, error)

func (*Client) HeadJson

func (c *Client) HeadJson(url string, headers map[string]string, body, data interface{}) error

func (*Client) HeadJsonCtx

func (c *Client) HeadJsonCtx(ctx context.Context, opName, url string, headers map[string]string, body, data interface{}) error

func (*Client) Post

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

func (*Client) PostCtx

func (c *Client) PostCtx(
	ctx context.Context, opName, url string, headers map[string]string, body interface{},
) (*Response, error)

func (*Client) PostJson

func (c *Client) PostJson(url string, headers map[string]string, body, data interface{}) error

func (*Client) PostJsonCtx

func (c *Client) PostJsonCtx(ctx context.Context, opName, url string, headers map[string]string, body, data interface{}) error

func (*Client) Put

func (c *Client) Put(url string, headers map[string]string, body interface{}) (*Response, error)

func (*Client) PutCtx

func (c *Client) PutCtx(
	ctx context.Context, opName, url string, headers map[string]string, body interface{},
) (*Response, error)

func (*Client) PutJson

func (c *Client) PutJson(url string, headers map[string]string, body, data interface{}) error

func (*Client) PutJsonCtx

func (c *Client) PutJsonCtx(ctx context.Context, opName, url string, headers map[string]string, body, data interface{}) error

type CodeMessageData

type CodeMessageData struct {
	Code, Message string
	Data          interface{}
}

func (*CodeMessageData) ValidateResponse

func (cmd *CodeMessageData) ValidateResponse(resp *Response) error

type Response

type Response struct {
	*http.Response

	UnmarshalFunc func(data []byte, v interface{}) error
	// contains filtered or unexported fields
}

func Delete

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

func DeleteCtx

func DeleteCtx(
	ctx context.Context, opName, url string, headers map[string]string, body interface{},
) (*Response, error)

func Get

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

func GetCtx

func GetCtx(
	ctx context.Context, opName, url string, headers map[string]string, body interface{},
) (*Response, error)
func Head(url string, headers map[string]string, body interface{}) (*Response, error)

func HeadCtx

func HeadCtx(
	ctx context.Context, opName, url string, headers map[string]string, body interface{},
) (*Response, error)

func Post

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

func PostCtx

func PostCtx(
	ctx context.Context, opName, url string, headers map[string]string, body interface{},
) (*Response, error)

func Put

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

func PutCtx

func PutCtx(
	ctx context.Context, opName, url string, headers map[string]string, body interface{},
) (*Response, error)

func (*Response) Body

func (resp *Response) Body() []byte

func (*Response) Check

func (resp *Response) Check(codes ...int) error

func (*Response) CodeError

func (resp *Response) CodeError() error

func (*Response) GetUnmarshalFunc

func (resp *Response) GetUnmarshalFunc() func(data []byte, v interface{}) error

func (*Response) Json

func (resp *Response) Json(data interface{}) error

func (*Response) Ok

func (resp *Response) Ok() error

Jump to

Keyboard shortcuts

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