link

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CONST = map[string]int{
	"OPT_AUTOREFERER":       toolpkg.OPT_AUTOREFERER,
	"OPT_FOLLOWLOCATION":    toolpkg.OPT_FOLLOWLOCATION,
	"OPT_CONNECTTIMEOUT":    toolpkg.OPT_CONNECTTIMEOUT,
	"OPT_CONNECTTIMEOUT_MS": toolpkg.OPT_CONNECTTIMEOUT_MS,
	"OPT_MAXREDIRS":         toolpkg.OPT_MAXREDIRS,
	"OPT_PROXYTYPE":         toolpkg.OPT_PROXYTYPE,
	"OPT_TIMEOUT":           toolpkg.OPT_TIMEOUT,
	"OPT_TIMEOUT_MS":        toolpkg.OPT_TIMEOUT_MS,
	"OPT_COOKIEJAR":         toolpkg.OPT_COOKIEJAR,
	"OPT_INTERFACE":         toolpkg.OPT_INTERFACE,
	"OPT_PROXY":             toolpkg.OPT_PROXY,
	"OPT_REFERER":           toolpkg.OPT_REFERER,
	"OPT_USERAGENT":         toolpkg.OPT_USERAGENT,
	"OPT_REDIRECT_POLICY":   toolpkg.OPT_REDIRECT_POLICY,
	"OPT_PROXY_FUNC":        toolpkg.OPT_PROXY_FUNC,
	"OPT_DEBUG":             toolpkg.OPT_DEBUG,
	"OPT_UNSAFE_TLS":        toolpkg.OPT_UNSAFE_TLS,
	"OPT_CONTEXT":           toolpkg.OPT_CONTEXT,
}

CONST String map of options

Functions

This section is empty.

Types

type Error

type Error struct {
	Code    int
	Message string
}

Custom error

func (Error) Error

func (err Error) Error() string

Implement the error interface

type HttpClient

type HttpClient struct {

	// Default headers of client client.
	Headers map[string]string
	// contains filtered or unexported fields
}

HttpClient Powerful and easy to use HTTP client.

func DefaultClient

func DefaultClient() *HttpClient

func NewHttpClient

func NewHttpClient() *HttpClient

NewHttpClient Create an HTTP client.

func (*HttpClient) Begin

func (client *HttpClient) Begin() *HttpClient

Begin marks the begining of a request, it's necessary for concurrent requests.

func (*HttpClient) Defaults

func (client *HttpClient) Defaults(defaults Map) *HttpClient

Defaults Set default options and headers.

func (*HttpClient) Delete

func (client *HttpClient) Delete(url string, params ...interface{}) (*Response, error)

Delete The DELETE request

func (*HttpClient) Do

func (client *HttpClient) Do(method string, url string, heads map[string]string, body io.Reader) (*Response, error)

Do Start a request, and get the response.

func (*HttpClient) Get

func (client *HttpClient) Get(url string, params ...interface{}) (*Response, error)

Get The GET request

func (*HttpClient) Head

func (client *HttpClient) Head(url string) (*Response, error)

Head The HEAD request

func (*HttpClient) Post

func (client *HttpClient) Post(url string, params interface{}) (*Response, error)

Post The POST request

With multipart set to true, the request will be encoded as "multipart/form-data".

If any of the params key starts with "@", it is considered as a form file (similar to CURL but different).

func (*HttpClient) PostJson

func (client *HttpClient) PostJson(url string, data interface{}) (*Response, error)

func (*HttpClient) PostMultipart

func (client *HttpClient) PostMultipart(url string, params interface{}) (*Response, error)

PostMultipart Post with the request encoded as "multipart/form-data".

func (*HttpClient) Put

func (client *HttpClient) Put(url string, body io.Reader) (*Response, error)

Put The PUT request

func (*HttpClient) PutJson

func (client *HttpClient) PutJson(url string, data interface{}) (*Response, error)

PutJson Put json data

func (*HttpClient) WithCommonHeader

func (client *HttpClient) WithCommonHeader(appName, appSecretKey string) *HttpClient

func (*HttpClient) WithHeader

func (client *HttpClient) WithHeader(k string, v string) *HttpClient

WithHeader Temporarily specify a header of the current request.

func (*HttpClient) WithHeaders

func (client *HttpClient) WithHeaders(m map[string]string) *HttpClient

WithHeaders Temporarily specify multiple headers of the current request.

func (*HttpClient) WithITrace

func (client *HttpClient) WithITrace(ctx *gin.Context) *HttpClient

func (*HttpClient) WithOption

func (client *HttpClient) WithOption(k int, v interface{}) *HttpClient

WithOption Temporarily specify an option of the current request.

func (*HttpClient) WithOptions

func (client *HttpClient) WithOptions(m Map) *HttpClient

WithOptions Temporarily specify multiple options of the current request.

type Map

type Map map[interface{}]interface{}

Map is a mixed structure with options and headers

type RequestLog

type RequestLog struct {
	URL     string            `json:"url"`
	Method  string            `json:"method"`
	IP      []string          `json:"ip"`
	Path    string            `json:"path"`
	Headers map[string]string `json:"headers"`
	Query   interface{}       `json:"query"`
	Body    interface{}       `json:"body"`
}

type Response

type Response struct {
	*http.Response
}

Response Thin wrapper of http.Response(can also be used as http.Response).

func (*Response) ReadAll

func (client *Response) ReadAll() ([]byte, error)

ReadAll Read response body into a byte slice.

func (*Response) ToString

func (client *Response) ToString() (string, error)

ToString Read response body into string.

Jump to

Keyboard shortcuts

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