xhttp

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NULL     = ""
	SUCCESS  = "SUCCESS"
	FAIL     = "FAIL"
	OK       = "OK"
	DebugOff = 0
	DebugOn  = 1
	Version  = "1.5.97"
)
View Source
const (
	GET    = "GET"
	POST   = "POST"
	PUT    = "PUT"
	DELETE = "DELETE"
	PATCH  = "PATCH"

	ResTypeJSON = "json"
	ResTypeXML  = "xml"

	TypeJSON              = "json"
	TypeXML               = "xml"
	TypeFormData          = "form-data"
	TypeMultipartFormData = "multipart-form-data"
)

Variables

View Source
var (
	MissWechatInitParamErr = errors.New("missing wechat init parameter")
	MissAlipayInitParamErr = errors.New("missing alipay init parameter")
	MissPayPalInitParamErr = errors.New("missing paypal init parameter")
	MissAppleInitParamErr  = errors.New("missing apple init parameter")
	MissLakalaInitParamErr = errors.New("missing lakala init parameter")
	MissParamErr           = errors.New("missing required parameter")
	MarshalErr             = errors.New("marshal error")
	UnmarshalErr           = errors.New("unmarshal error")
	SignatureErr           = errors.New("signature error")
	VerifySignatureErr     = errors.New("verify signature error")
	CertNotMatchErr        = errors.New("cert not match error")
	GetSignDataErr         = errors.New("get signature data error")
)

Functions

func FormatURLParam

func FormatURLParam(body map[string]any) (urlParam string)

Types

type BodyMap

type BodyMap map[string]any

func (BodyMap) CheckEmptyError

func (bm BodyMap) CheckEmptyError(keys ...string) error

func (BodyMap) CheckNotAllEmptyError

func (bm BodyMap) CheckNotAllEmptyError(keys ...string) error

func (BodyMap) EncodeAliPaySignParams

func (bm BodyMap) EncodeAliPaySignParams() string

("bar=baz&foo=quux") sorted by key.

func (BodyMap) EncodeURLParams

func (bm BodyMap) EncodeURLParams() string

("bar=baz&foo=quux") sorted by key.

func (BodyMap) EncodeWeChatSignParams

func (bm BodyMap) EncodeWeChatSignParams(apiKey string) string

("bar=baz&foo=quux") sorted by key.

func (BodyMap) Get

func (bm BodyMap) Get(key string) string

获取参数,同 GetString()

func (BodyMap) GetInterface

func (bm BodyMap) GetInterface(key string) any

获取原始参数

func (BodyMap) GetString

func (bm BodyMap) GetString(key string) string

获取参数转换string

func (BodyMap) JsonBody

func (bm BodyMap) JsonBody() (jb string)

func (BodyMap) MarshalXML

func (bm BodyMap) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error)

func (BodyMap) Remove

func (bm BodyMap) Remove(key string)

删除参数

func (BodyMap) Reset

func (bm BodyMap) Reset()

置空BodyMap

func (BodyMap) Set

func (bm BodyMap) Set(key string, value any) BodyMap

设置参数

func (BodyMap) SetBodyMap

func (bm BodyMap) SetBodyMap(key string, value func(b BodyMap)) BodyMap

func (BodyMap) SetFormFile

func (bm BodyMap) SetFormFile(key string, file *util.File) BodyMap

设置 FormFile

func (BodyMap) Unmarshal

func (bm BodyMap) Unmarshal(ptr any) (err error)

Unmarshal to struct or slice point

func (*BodyMap) UnmarshalXML

func (bm *BodyMap) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

type Client

type Client struct {
	HttpClient *http.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient() (client *Client)

NewClient , default tls.Config{InsecureSkipVerify: true}

func (*Client) Req

func (c *Client) Req(typeStr ...string) *Request

typeStr is request type and response type default is TypeJSON first param is request type second param is response data type

func (*Client) SetBodySize

func (c *Client) SetBodySize(sizeMB int) (client *Client)

set body size (MB), default is 10MB

func (*Client) SetTLSConfig

func (c *Client) SetTLSConfig(tlsCfg *tls.Config) (client *Client)

func (*Client) SetTimeout

func (c *Client) SetTimeout(timeout time.Duration) (client *Client)

func (*Client) SetTransport

func (c *Client) SetTransport(transport *http.Transport) (client *Client)

type DebugSwitch

type DebugSwitch int8

type Request

type Request struct {
	Header http.Header
	// contains filtered or unexported fields
}

func (*Request) Delete

func (r *Request) Delete(url string) *Request

func (*Request) EndBytes

func (r *Request) EndBytes(ctx context.Context) (res *http.Response, bs []byte, err error)

func (*Request) EndStruct

func (r *Request) EndStruct(ctx context.Context, v any) (res *http.Response, err error)

func (*Request) Get

func (r *Request) Get(url string) *Request

func (*Request) Patch

func (r *Request) Patch(url string) *Request

func (*Request) Post

func (r *Request) Post(url string) *Request

func (*Request) Put

func (r *Request) Put(url string) *Request

func (*Request) SendBodyMap

func (r *Request) SendBodyMap(bm map[string]any) (client *Request)

func (*Request) SendMultipartBodyMap

func (r *Request) SendMultipartBodyMap(bm map[string]any) (client *Request)

func (*Request) SendString

func (r *Request) SendString(encodeStr string) (client *Request)

encodeStr: url.Values.Encode() or jsonBody

func (*Request) SendStruct

func (r *Request) SendStruct(v any) (c *Request)

Jump to

Keyboard shortcuts

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