wukong

package
v1.0.35 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MimeTypeJSON       = "application/json"
	MimeTypeJSON1      = "text/json"
	MimeTypeJSON2      = "json"
	MimeTypeXML        = "application/xml"
	MimeTypeXML1       = "text/xml"
	MimeTypeXML2       = "/xml"
	MimeTypeFormData   = "application/x-www-form-urlencoded"
	MimeTypeUrlencoded = "application/x-www-form-urlencoded"
	MimeTypeHTML       = "text/html"
	MimeTypeText       = "text/plain"
	MimeTypeMultipart  = "multipart/form-data"
)

Variables

This section is empty.

Functions

func Decode

func Decode(contentType string, val interface{}) ([]byte, error)

func Encode

func Encode(contentType string, data []byte, val interface{}) error

Types

type After

type After func(*Request, *Response) error

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

type Before

type Before func(*Request) error

type Encoder

type Encoder interface {
	MimeType() string                          // mime type
	Encode(data []byte, val interface{}) error // encode data to val struct
	Decode(val interface{}) ([]byte, error)    // decode value to data
}

type JSONEncoder

type JSONEncoder struct{}

func (*JSONEncoder) Decode

func (c *JSONEncoder) Decode(v interface{}) ([]byte, error)

func (*JSONEncoder) Encode

func (c *JSONEncoder) Encode(data []byte, val interface{}) error

func (*JSONEncoder) MimeType

func (c *JSONEncoder) MimeType() string

type LoggerLevel added in v1.0.0

type LoggerLevel int
const (
	LoggerDisable LoggerLevel = 1 << iota
	LoggerRequest
	LoggerResponse
	LoggerCurl
)

type MultipartForm added in v1.0.18

type MultipartForm struct {
	IsFile    bool
	FieldName string
	Filename  string
	Value     io.Reader
}

type Request

type Request struct {
	TraceInfo   TraceInfo
	Context     context.Context
	BasicAuth   BasicAuth
	Error       error
	Method      string
	BaseUrl     string
	Url         string
	ContentType string
	Header      http.Header
	QueryData   url.Values
	FormData    url.Values
	ParamData   map[string]interface{}
	BodyData    interface{}
	Cookies     []*http.Cookie
	Multipart   []MultipartForm
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(client *WuKong, method, path string) *Request

func (*Request) AddCookies

func (request *Request) AddCookies(cookies ...*http.Cookie) *Request

func (*Request) End

func (request *Request) End() *Response

func (*Request) Form

func (request *Request) Form(form interface{}) *Request

func (*Request) Logger added in v1.0.0

func (request *Request) Logger(level LoggerLevel) *Request

func (*Request) Metric added in v1.0.0

func (request *Request) Metric(enable bool) *Request

func (*Request) Param

func (request *Request) Param(param map[string]interface{}) *Request

Param Method sets multiple URL path key-value pairs.

For example: http://example.com/users/:uid

client.Get("http://example.com/users/:uid").Param(map[string]interface{}{"uid": "123"}).End()

request target Url will be replace to `http://example.com/users/123`

func (*Request) Query

func (request *Request) Query(query interface{}) *Request

Query format:

1.map[string]interface{} {"key": "value", "key1": 1}

func (*Request) RawRequest

func (request *Request) RawRequest() (*http.Request, error)

func (*Request) Send

func (request *Request) Send(data interface{}) *Request

func (*Request) SendFile added in v1.0.18

func (request *Request) SendFile(fieldName, filename string) *Request

func (*Request) SendFileReader added in v1.0.18

func (request *Request) SendFileReader(fieldName, filename string, reader io.Reader) *Request

func (*Request) Set

func (request *Request) Set(key, value interface{}) *Request

func (*Request) SetBasicAuth

func (request *Request) SetBasicAuth(auth BasicAuth) *Request

func (*Request) SetHeader

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

SetHeader set Header

func (*Request) Type

func (request *Request) Type(typ string) *Request

func (*Request) WithCTX

func (request *Request) WithCTX(ctx context.Context) *Request

type Response

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

func NewResponse

func NewResponse(err error, req *Request, resp *http.Response) *Response

func (*Response) BindBody

func (resp *Response) BindBody(data interface{}) *Response

func (*Response) BindBytes

func (resp *Response) BindBytes(b *[]byte) *Response

func (*Response) BindError

func (resp *Response) BindError(err *error) *Response

func (*Response) BindHeader

func (resp *Response) BindHeader(header *http.Header) *Response

func (*Response) BindIsCancel

func (resp *Response) BindIsCancel(ok *bool) *Response

func (*Response) BindIsTimeout

func (resp *Response) BindIsTimeout(ok *bool) *Response

func (*Response) BindStatus

func (resp *Response) BindStatus(status *string) *Response

func (*Response) BindStatusCode

func (resp *Response) BindStatusCode(code *int) *Response

func (*Response) Body

func (resp *Response) Body() io.ReadCloser

func (*Response) Bytes

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

func (*Response) ConditionBindBody

func (resp *Response) ConditionBindBody(check func(interface{}) bool, data ...interface{}) *Response

func (*Response) Error

func (resp *Response) Error() error

func (*Response) Header

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

func (*Response) IgnoreEncodeErr added in v1.0.0

func (resp *Response) IgnoreEncodeErr() *Response

func (*Response) IsCancel

func (resp *Response) IsCancel() bool

func (*Response) IsTimeout

func (resp *Response) IsTimeout() bool

func (*Response) Status

func (resp *Response) Status() string

func (*Response) StatusCode

func (resp *Response) StatusCode() int

type TraceInfo

type TraceInfo struct {
	HostPort               string
	GotConnInfo            httptrace.GotConnInfo
	DNSStartInfo           httptrace.DNSStartInfo
	DNSDoneInfo            httptrace.DNSDoneInfo
	ConnectNetwork         string
	ConnectAddr            string
	ConnectError           error
	TLSConnectionState     tls.ConnectionState
	TLSError               error
	ElapsedTime            time.Duration
	GetConnAt              time.Time
	GotConnAt              time.Time
	GetConnElapsed         time.Duration
	DNSStartAt             time.Time
	DNSDoneAt              time.Time
	DNSLookupElapsed       time.Duration
	ConnectStartAt         time.Time
	ConnectDoneAt          time.Time
	ConnectElapsed         time.Duration
	TLSHandshakeStartAt    time.Time
	TLSHandshakeDoneAt     time.Time
	TLSHandshakeElapsed    time.Duration
	GotFirstResponseByteAt time.Time
}

type WuKong

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

func New

func New(baseUrl string) *WuKong

func (*WuKong) Client added in v1.0.0

func (wk *WuKong) Client() *http.Client

func (*WuKong) Delete

func (wk *WuKong) Delete(path string) *Request

func (*WuKong) Get

func (wk *WuKong) Get(path string) *Request

func (*WuKong) Head

func (wk *WuKong) Head(path string) *Request

func (*WuKong) Logger added in v1.0.0

func (wk *WuKong) Logger(lv LoggerLevel) *WuKong

func (*WuKong) Metric added in v1.0.0

func (wk *WuKong) Metric(enable bool) *WuKong

func (*WuKong) Options

func (wk *WuKong) Options(path string) *Request

func (*WuKong) Patch

func (wk *WuKong) Patch(path string) *Request

func (*WuKong) Post

func (wk *WuKong) Post(path string) *Request

func (*WuKong) Put

func (wk *WuKong) Put(path string) *Request

func (*WuKong) SetBasicAuth

func (wk *WuKong) SetBasicAuth(auth BasicAuth) *WuKong

func (*WuKong) SetHeader added in v1.0.0

func (wk *WuKong) SetHeader(header map[string]string) *WuKong

func (*WuKong) SetQuery added in v1.0.0

func (wk *WuKong) SetQuery(query map[string]string) *WuKong

func (*WuKong) SetTransport

func (wk *WuKong) SetTransport(transport *http.Transport) *WuKong

func (*WuKong) Timeout

func (wk *WuKong) Timeout(t time.Duration) *WuKong

func (*WuKong) Trace

func (wk *WuKong) Trace(path string) *Request

func (*WuKong) UseAfter

func (wk *WuKong) UseAfter(fns ...After) *WuKong

func (*WuKong) UseBefore

func (wk *WuKong) UseBefore(fns ...Before) *WuKong

type XMLEncoder

type XMLEncoder struct{}

func (*XMLEncoder) Decode

func (c *XMLEncoder) Decode(v interface{}) ([]byte, error)

func (*XMLEncoder) Encode

func (c *XMLEncoder) Encode(data []byte, val interface{}) error

func (*XMLEncoder) MimeType

func (c *XMLEncoder) MimeType() string

Jump to

Keyboard shortcuts

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