_http

package
v0.0.0-...-b41c23d Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONTENT_TYPE          = "Content-Type"
	JSON                  = "application/json"
	JSON_UTF8             = "application/json; charset=utf-8"
	X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded"
	FORM_DATA             = "multipart/form-data"
	TEXT_XML              = "text/xml"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Headers

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

func NewHeaders

func NewHeaders() *Headers

func (*Headers) Copy

func (p *Headers) Copy() *Headers

func (*Headers) Get

func (p *Headers) Get(name string) string

func (*Headers) Headers

func (p *Headers) Headers() map[string]string

func (*Headers) Set

func (p *Headers) Set(name, val string)

type Json

type Json map[string]interface{}

func (Json) AsPayload

func (p Json) AsPayload() bool

func (Json) Key

func (p Json) Key() string

func (Json) Value

func (p Json) Value() (interface{}, error)

type Method

type Method string
const (
	POST   Method = "POST"
	GET    Method = "GET"
	PUT    Method = "PUT"
	DELETE Method = "DELETE"
	HEAD   Method = "HEAD"
)

type Parser

type Parser func(data []byte) (result interface{}, err error)

func StatusDataParser

func StatusDataParser(pointer interface{}) Parser

func StatusParser

func StatusParser() Parser

type Reader

type Reader interface {
	Key() string
	Value() interface{}
	AsPayload() bool
}

func File

func File(key string, path string) Reader

func Param

func Param(key string, value interface{}) Reader

func Payload

func Payload(v interface{}) Reader

type Request

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

func NewRequest

func NewRequest(method Method, url string, params ...Reader) *Request

func (*Request) Copy

func (p *Request) Copy() *Request

func (*Request) Delete

func (p *Request) Delete(url string, params ...Reader) *Response

func (*Request) Exec

func (p *Request) Exec() *Response

func (*Request) Get

func (p *Request) Get(url string, params ...Reader) *Response

func (*Request) Header

func (p *Request) Header() http.Header

func (*Request) Method

func (p *Request) Method() Method

func (*Request) Name

func (p *Request) Name() string

func (*Request) Origin

func (p *Request) Origin() *http.Request

func (*Request) Params

func (p *Request) Params() []Reader

func (*Request) Post

func (p *Request) Post(url string, params ...Reader) *Response

func (*Request) Put

func (p *Request) Put(url string, params ...Reader) *Response

func (*Request) Send

func (p *Request) Send(method Method, url string, params ...Reader) (response *Response)

func (*Request) SetContentType

func (p *Request) SetContentType(contentType string) *Request

func (*Request) SetFailedCallback

func (p *Request) SetFailedCallback(failedCallback func(response *Response)) *Request

func (*Request) SetHeader

func (p *Request) SetHeader(key, value string) *Request

func (*Request) SetMethod

func (p *Request) SetMethod(method Method) *Request

func (*Request) SetName

func (p *Request) SetName(name string) *Request

func (*Request) SetParams

func (p *Request) SetParams(params []Reader) *Request

func (*Request) SetSuccessCallback

func (p *Request) SetSuccessCallback(successCallback func(response *Response)) *Request

func (*Request) SetTimeout

func (p *Request) SetTimeout(timeout time.Duration) *Request

func (*Request) SetUrl

func (p *Request) SetUrl(url string) *Request

func (*Request) Url

func (p *Request) Url() string

type Response

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

func Delete

func Delete(url string, params ...Reader) *Response

func Get

func Get(url string, params ...Reader) *Response

func NewResponse

func NewResponse() *Response

func Post

func Post(url string, params ...Reader) *Response

func Put

func Put(url string, params ...Reader) *Response

func Send

func Send(method Method, url string, params ...Reader) *Response

func (*Response) Body

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

func (*Response) Code

func (p *Response) Code() int

func (*Response) Cost

func (p *Response) Cost() time.Duration

func (*Response) Error

func (p *Response) Error() error

func (*Response) Header

func (p *Response) Header() http.Header

func (*Response) Json

func (p *Response) Json() (*_json.Json, error)

func (*Response) Name

func (p *Response) Name() string

func (*Response) Parse

func (p *Response) Parse(parser Parser) (data interface{}, err error)

func (*Response) Request

func (p *Response) Request() *Request

func (*Response) Status

func (p *Response) Status() string

func (*Response) String

func (p *Response) String() string

type Responses

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

func (*Responses) Add

func (p *Responses) Add(response *Response)

func (*Responses) All

func (p *Responses) All() []*Response

func (*Responses) Error

func (p *Responses) Error() error

func (*Responses) Get

func (p *Responses) Get(name string) *Response

type Scheduler

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

func NewScheduler

func NewScheduler() *Scheduler

func (*Scheduler) Delete

func (p *Scheduler) Delete(url string, params ...Reader) *Response

func (*Scheduler) Parallel

func (p *Scheduler) Parallel(requests ...*Request) *Responses

Parallel 并发执行所有请求, 返回所有结果,要求每一个 Request 拥有 name 属性,且不冲突

func (*Scheduler) Post

func (p *Scheduler) Post(url string, params ...Reader) *Response

func (*Scheduler) Put

func (p *Scheduler) Put(url string, params ...Reader) *Response

func (*Scheduler) Rand

func (p *Scheduler) Rand(requests ...*Request) *Response

Rand 随机执行,根据请求数抛出随机数选择一个执行,直到请求成功,或全部失败后返回

func (*Scheduler) Send

func (p *Scheduler) Send(method Method, url string, params ...Reader) (response *Response)

func (*Scheduler) Series

func (p *Scheduler) Series(requests ...*Request) *Response

Series 串行执行请求,直到请求成功,或全部失败后返回

func (*Scheduler) SetContentType

func (p *Scheduler) SetContentType(contentType string)

func (*Scheduler) SetHeader

func (p *Scheduler) SetHeader(key, value string)

func (*Scheduler) SetHost

func (p *Scheduler) SetHost(host string)

type Status

type Status struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"params"`
}

Jump to

Keyboard shortcuts

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