xhttp

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: Apache-2.0 Imports: 16 Imported by: 19

README

xhttp

http request library for Go

Documentation

Index

Constants

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

This section is empty.

Functions

func ConvertToString

func ConvertToString(v any) (str string)

func FormatURLParam

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

Types

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 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