ghttp

package module
v0.0.0-...-72a19b6 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 9 Imported by: 0

README

ghttp

A simple HTTP library

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJSONResponse

func DecodeJSONResponse(resp *http.Response) (map[string]interface{}, error)

DecodeJSONResponse decode the response data to a JSON object

func ParseError

func ParseError(err error) int

ParseError convert *url.Error to HTTP status codes

Types

type Client

type Client struct {
	URL string
	// contains filtered or unexported fields
}

Client is a wrap of http.Client to fit our usage

func NewClient

func NewClient(tlsConfig *tls.Config, timeout ...time.Duration) *Client

NewClient creates a new Client

func (*Client) AppendUA

func (c *Client) AppendUA(ua string) *Client

AppendUA appends the given string to current User-Agent

func (*Client) Clone

func (c *Client) Clone() *Client

Clone makes a copy of current Client

func (*Client) DefaultUAWithComment

func (c *Client) DefaultUAWithComment(ua string) *Client

DefaultUAWithComment sets the comment block of default UA and use it

func (*Client) Delete

func (c *Client) Delete() (*http.Response, error)

Delete build a DELETE request and send it to server

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do is a wrap of http.Client.Do(), that send the request directly to server

func (*Client) Get

func (c *Client) Get() (*http.Response, error)

Get is a wrap of http.Client.Get(), that send the GET request to server

func (*Client) Head

func (c *Client) Head() (*http.Response, error)

Head is a wrap of http.Client.Head(), that send the HEAD request to server

func (*Client) Patch

func (c *Client) Patch(body io.Reader) (*http.Response, error)

Patch build a PATCH request and send it to server

func (*Client) Post

func (c *Client) Post(body io.Reader) (*http.Response, error)

Post build a POST request and send it to server

func (*Client) PostForm

func (c *Client) PostForm(data url.Values) (*http.Response, error)

PostForm is a wrap of http.Client.PostForm(), that send the POST request with form to server

func (*Client) Put

func (c *Client) Put(body io.Reader) (*http.Response, error)

Put build a PUT request and send it to server

func (*Client) UseSocks5Proxy

func (c *Client) UseSocks5Proxy(ps string) error

UseSocks5Proxy set the client to use a Socks5 Proxy for requests

func (*Client) WithAccept

func (c *Client) WithAccept(a string) *Client

WithAccept set the accept header to given string

func (*Client) WithContentT

func (c *Client) WithContentT(ct string) *Client

WithContentT set the content type header to given string

func (*Client) WithUA

func (c *Client) WithUA(ua string) *Client

WithUA set the user agent header to given string

func (*Client) WithURL

func (c *Client) WithURL(url string) *Client

WithURL set the URL in client to given string

Jump to

Keyboard shortcuts

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