convhttp

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = newDefaultClient()

DefaultClient default client

Functions

This section is empty.

Types

type Binder

type Binder interface {
	// Name returns the binding engine name
	Name() string
	// Bind binds the passed struct pointer using the specified binding engine.
	Bind(data []byte, obj interface{}) error
}

Binder binder

type Client

type Client struct {
	*http.Client
	Logger *zap.Logger
}

Client client

func (*Client) Do

func (c *Client) Do(opts *RequestOptions, interceptors ...ResponseInterceptor) (resp *Response)

Do sends an HTTP request based on RequestOptions and then delegates the response to all specified iterceptors.

type FormData

type FormData struct {
	url.Values
	// contains filtered or unexported fields
}

FormData form data

func NewFormData

func NewFormData() *FormData

NewFormData new from data instance

func (*FormData) MarshalJSON

func (fd *FormData) MarshalJSON() ([]byte, error)

MarshalJSON implements MarshalJSON method to produce JSON.

func (*FormData) WithFile

func (fd *FormData) WithFile(fieldname string, filename string, data []byte)

WithFile with file

type JSONBinder

type JSONBinder struct{}

JSONBinder json binder

func (*JSONBinder) Bind

func (b *JSONBinder) Bind(data []byte, obj interface{}) error

Bind binds the passed struct pointer using json binding engine.

func (*JSONBinder) Name

func (b *JSONBinder) Name() string

Name returns the binding engine name

type RequestOptions

type RequestOptions struct {
	Method  string      `json:"method,omitempty"`
	URL     string      `json:"url,omitempty"`
	Header  http.Header `json:"header,omitempty"`
	Query   url.Values  `json:"query,omitempty"`
	Request interface{} `json:"request,omitempty"`
}

RequestOptions request options

type Response

type Response struct {
	*http.Response
	Request *RequestOptions
	Body    []byte
	// contains filtered or unexported fields
}

Response response

func (*Response) Error

func (resp *Response) Error() error

Error returns the error

func (*Response) ShouldBindJSON

func (resp *Response) ShouldBindJSON(obj interface{}) error

ShouldBindJSON is a shortcut for resp.ShouldBindWith(obj, &JSONBinder{}).

func (*Response) ShouldBindWith

func (resp *Response) ShouldBindWith(obj interface{}, binder Binder) (err error)

ShouldBindWith binds the passed struct pointer using the specified binding engine.

type ResponseInterceptor added in v0.1.1

type ResponseInterceptor func(resp *Response) error

ResponseInterceptor intercepts the response. ResponseInterceptor counld be specified as a customize error handler. Errors returned from ResponseInterceptor will be set into Response.err field.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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