zhttp

package
v0.1.27 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2020 License: MIT Imports: 27 Imported by: 9

Documentation

Overview

Package zhttp provides http client related operations

Index

Constants

View Source
const (
	BitReqHead = 1 << iota
	BitReqBody
	BitRespHead
	BitRespBody
	BitTime
	BitStdFlags = BitReqHead | BitReqBody | BitRespHead | BitRespBody
)

Variables

View Source
var (
	ErrNoTransport     = errors.New("no transport")
	ErrUrlNotSpecified = errors.New("url not specified")
	ErrTransEmpty      = errors.New("trans is empty")
	ErrNoMatched       = errors.New("no file have been matched")
)
View Source
var (
	Debug = false
)

Functions

func BodyJSON

func BodyJSON(v interface{}) *bodyJson

BodyJSON make the object be encoded in json format and set it to the request body

func BodyXML

func BodyXML(v interface{}) *bodyXml

BodyXML make the object be encoded in xml format and set it to the request body

func Client

func Client() *http.Client

func EnableCookie

func EnableCookie(enable bool)

func EnableInsecureTLS

func EnableInsecureTLS(enable bool)

func File

func File(patterns ...string) interface{}

func Flags

func Flags() int

func RemoveProxy added in v0.1.26

func RemoveProxy() error

func SetClient

func SetClient(client *http.Client)

func SetFlags

func SetFlags(flags int)

func SetJSONEscapeHTML

func SetJSONEscapeHTML(escape bool)

func SetJSONIndent

func SetJSONIndent(prefix, indent string)

func SetProxy

func SetProxy(proxy func(*http.Request) (*url.URL, error)) error

func SetProxyUrl

func SetProxyUrl(rawurl string) error

func SetTimeout

func SetTimeout(d time.Duration)

func SetXMLIndent

func SetXMLIndent(prefix, indent string)

Types

type DownloadProgress

type DownloadProgress func(current, total int64)

type Engine

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

func New

func New() *Engine

New create a new *Engine

func (*Engine) CheckRedirect added in v0.0.19

func (r *Engine) CheckRedirect(fn ...func(req *http.Request, via []*http.Request) error)

func (*Engine) Client

func (r *Engine) Client() *http.Client

func (*Engine) Delete

func (r *Engine) Delete(url string, v ...interface{}) (*Res, error)

func (*Engine) Do

func (r *Engine) Do(method, rawurl string, vs ...interface{}) (resp *Res, err error)

func (*Engine) EnableCookie

func (r *Engine) EnableCookie(enable bool)

func (*Engine) EnableInsecureTLS

func (r *Engine) EnableInsecureTLS(enable bool)

func (*Engine) Get

func (r *Engine) Get(url string, v ...interface{}) (*Res, error)

func (*Engine) GetFlags

func (r *Engine) GetFlags() int

func (*Engine) Head

func (r *Engine) Head(url string, v ...interface{}) (*Res, error)

func (*Engine) Options

func (r *Engine) Options(url string, v ...interface{}) (*Res, error)

func (*Engine) Patch

func (r *Engine) Patch(url string, v ...interface{}) (*Res, error)

func (*Engine) Post

func (r *Engine) Post(url string, v ...interface{}) (*Res, error)

func (*Engine) Put

func (r *Engine) Put(url string, v ...interface{}) (*Res, error)

func (*Engine) RemoveProxy added in v0.1.26

func (r *Engine) RemoveProxy() error

func (*Engine) SetClient

func (r *Engine) SetClient(client *http.Client)

func (*Engine) SetFlags

func (r *Engine) SetFlags(flags int)

func (*Engine) SetJSONEscapeHTML

func (r *Engine) SetJSONEscapeHTML(escape bool)

func (*Engine) SetJSONIndent

func (r *Engine) SetJSONIndent(prefix, indent string)

func (*Engine) SetProxy

func (r *Engine) SetProxy(proxy func(*http.Request) (*url.URL, error)) error

func (*Engine) SetProxyUrl

func (r *Engine) SetProxyUrl(rawurl string) error

func (*Engine) SetSsl

func (r *Engine) SetSsl(certPath, keyPath, CAPath string) (*tls.Config, error)

func (*Engine) SetTimeout

func (r *Engine) SetTimeout(d time.Duration)

func (*Engine) SetXMLIndent

func (r *Engine) SetXMLIndent(prefix, indent string)

type FileUpload

type FileUpload struct {
	FileName  string
	FieldName string
	File      io.ReadCloser
}
type Header map[string]string

func (Header) Clone

func (h Header) Clone() Header

type Host

type Host string

type Param

type Param map[string]interface{}

type QueryParam

type QueryParam map[string]interface{}

type Res

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

func Delete

func Delete(url string, v ...interface{}) (*Res, error)

func Do

func Do(method, url string, v ...interface{}) (*Res, error)

func Get

func Get(url string, v ...interface{}) (*Res, error)
func Head(url string, v ...interface{}) (*Res, error)

func Options

func Options(url string, v ...interface{}) (*Res, error)

func Patch

func Patch(url string, v ...interface{}) (*Res, error)

func Post

func Post(url string, v ...interface{}) (*Res, error)

func Put

func Put(url string, v ...interface{}) (*Res, error)

func (*Res) Body

func (r *Res) Body() (body io.ReadCloser)

func (*Res) Bytes

func (r *Res) Bytes() []byte

func (*Res) Cost

func (r *Res) Cost() time.Duration

func (*Res) Dump

func (r *Res) Dump() string

func (*Res) GetCookie

func (r *Res) GetCookie() map[string]*http.Cookie

func (*Res) Request

func (r *Res) Request() *http.Request

func (*Res) Response

func (r *Res) Response() *http.Response

func (*Res) String

func (r *Res) String() string

func (*Res) ToBytes

func (r *Res) ToBytes() ([]byte, error)

func (*Res) ToFile

func (r *Res) ToFile(name string) error

func (*Res) ToJSON

func (r *Res) ToJSON(v interface{}) error

func (*Res) ToString

func (r *Res) ToString() (string, error)

func (*Res) ToXML

func (r *Res) ToXML(v interface{}) error

func (Res) Upload

func (m Res) Upload(req *http.Request)

type UploadProgress

type UploadProgress func(current, total int64)

Jump to

Keyboard shortcuts

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