Documentation ¶
Index ¶
- Constants
- func DefaultLogger(url, method, auth string, reqBody, respBody *Body, status int, ...)
- func DisableLog()
- func DownloadFile(filepath, url string) error
- func DownloadImage(filepath, url string) error
- func GetFile(url string) (io.ReadCloser, error)
- func GetFileWithReqOption(url string, opts ...RequestOption) (io.ReadCloser, error)
- func GetImage(url string) (io.ReadCloser, error)
- func GetRandUserAgent() string
- func ImageOption(req *http.Request)
- func NewReplaceHttpRequest(r *http.Request) *replaceHttpRequest
- func ReplaceHttpRequest(r *http.Request, url, method string, body io.ReadCloser) *http.Request
- func ResolveURL(u *url.URL, p string) string
- func SetDefaultClient(client *http.Client)
- func SetDefaultLogger(logger LogCallback)
- func SetProxy(url string)
- func SetProxyEnv(url string)
- func SetTimeout(timeout time.Duration)
- func SimpleDelete(url string, param, response interface{}) error
- func SimpleGet(url string, response any) error
- func SimpleGetStream(url string) (io.ReadCloser, error)
- func SimplePost(url string, param, response interface{}) error
- func SimplePut(url string, param, response interface{}) error
- func UrlAppendParam(url string, param interface{}) string
- func UrlParam(param interface{}) string
- type Body
- type ContentType
- type Download
- func (d *Download) AddHeader(header, value string) *Download
- func (d *Download) DownloadFile(filepath string) error
- func (d *Download) GetReader() (io.ReadCloser, error)
- func (d *Download) RetainMode() *Download
- func (d *Download) SetClient(set func(*http.Client)) *Download
- func (d *Download) SetHeader(header Header) *Download
- func (d *Download) SetRequest(set RequestOption) *Download
- func (d *Download) WithClient(c *http.Client) *Download
- func (d *Download) WithOptions(opts ...RequestOption) *Download
- func (d *Download) WithRequest(c *http.Request) *Download
- type Header
- type LogCallback
- type Logger
- type Option
- type Pair
- type RawResponse
- type Request
- func (req *Request) AddHeader(k, v string) *Request
- func (req *Request) CacheDelete(url string, param, response interface{}) error
- func (req *Request) CacheDo(url, method string, param, response interface{}) error
- func (req *Request) CacheGet(url string, response interface{}) error
- func (req *Request) CachePost(url string, param, response interface{}) error
- func (req *Request) CachePut(url string, param, response interface{}) error
- func (req *Request) CachedHeader(key string) *Request
- func (req *Request) CompleteDo(url, method string, param, response interface{}) error
- func (req *Request) ContentType(contentType ContentType) *Request
- func (req *Request) Delete(url string, param, response interface{}) error
- func (req *Request) DisableLog() *Request
- func (req *Request) Do(param, response interface{}) error
- func (req *Request) DoEmpty() error
- func (req *Request) DoRaw(param interface{}) (RawResponse, error)
- func (req *Request) DoStream(param interface{}) (io.ReadCloser, error)
- func (req *Request) DoWithNoParam(response interface{}) error
- func (req *Request) DoWithNoResponse(param interface{}) error
- func (req *Request) Download(url, path string) error
- func (req *Request) EnableLog() *Request
- func (req *Request) Get(url string, response interface{}) error
- func (req *Request) Method(method string) *Request
- func (req *Request) Post(url string, param, response interface{}) error
- func (req *Request) Put(url string, param, response interface{}) error
- func (req *Request) ResponseHandler(handler func([]byte) ([]byte, error)) *Request
- func (req *Request) RetryHandler(handle func(*Request)) *Request
- func (req *Request) RetryTimes(retryTimes int) *Request
- func (req *Request) SetHeader(header Header) *Request
- func (req *Request) SetProxy(url string) *Request
- func (req *Request) Timeout(timeout time.Duration) *Request
- func (req *Request) Url(url string) *Request
- func (req *Request) WithClient(client *http.Client) *Request
- func (req *Request) WithLogger(logger LogCallback) *Request
- type RequestOption
- type ResponseBody
- type ResponseBody2
- type ResponseBodyCheck
Constants ¶
View Source
const ( UserAgent1 = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" UserAgent2 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36" )
Variables ¶
This section is empty.
Functions ¶
func DefaultLogger ¶
func DisableLog ¶
func DisableLog()
func DownloadFile ¶
func DownloadImage ¶
func GetFileWithReqOption ¶ added in v1.1.0
func GetFileWithReqOption(url string, opts ...RequestOption) (io.ReadCloser, error)
func GetRandUserAgent ¶
func GetRandUserAgent() string
func ImageOption ¶
func NewReplaceHttpRequest ¶
func ReplaceHttpRequest ¶
func SetDefaultClient ¶ added in v1.1.0
func SetDefaultLogger ¶
func SetDefaultLogger(logger LogCallback)
func SetProxyEnv ¶ added in v1.1.0
func SetProxyEnv(url string)
func SetTimeout ¶
func SimpleDelete ¶
func SimpleGetStream ¶
func SimpleGetStream(url string) (io.ReadCloser, error)
func SimplePost ¶
func UrlAppendParam ¶ added in v1.1.0
Types ¶
type Body ¶
type Body struct { Data []byte ContentType ContentType }
func NewBody ¶
func NewBody(data []byte, contentType ContentType) *Body
func (*Body) IsProtobuf ¶
type ContentType ¶
type ContentType uint8
const ( ContentTypeJson ContentType = iota ContentTypeForm ContentTypeFormData ContentTypeProtobuf ContentTypeText ContentTypeImage ContentTypeBinary )
type Download ¶
type Download struct { Client *http.Client Request *http.Request // contains filtered or unexported fields }
TODO: Range StatusPartialContent 下载
func NewDownload ¶ added in v1.1.0
func (*Download) DownloadFile ¶ added in v1.1.0
func (*Download) RetainMode ¶ added in v1.1.0
保留模式,如果文件已存在,不下载覆盖
func (*Download) SetRequest ¶ added in v1.1.0
func (d *Download) SetRequest(set RequestOption) *Download
func (*Download) WithClient ¶ added in v1.1.0
func (*Download) WithOptions ¶ added in v1.1.0
func (d *Download) WithOptions(opts ...RequestOption) *Download
type LogCallback ¶
type RawResponse ¶
type RawResponse = []byte
type Request ¶
type Request struct {
AuthUser, AuthPass string
// contains filtered or unexported fields
}
Request ...
func DefaultHeaderRequest ¶ added in v1.1.0
func DefaultHeaderRequest() *Request
func NewDeleteRequest ¶
func NewGetRequest ¶
func NewPostRequest ¶
func NewPutRequest ¶
func NewRequest ¶
func (*Request) CacheDelete ¶
func (*Request) CachedHeader ¶
func (*Request) CompleteDo ¶
func (*Request) ContentType ¶
func (req *Request) ContentType(contentType ContentType) *Request
func (*Request) DisableLog ¶
func (*Request) DoRaw ¶
func (req *Request) DoRaw(param interface{}) (RawResponse, error)
func (*Request) DoWithNoParam ¶
func (*Request) DoWithNoResponse ¶
func (*Request) ResponseHandler ¶
func (*Request) RetryHandler ¶ added in v1.1.0
func (*Request) RetryTimes ¶
func (*Request) WithLogger ¶
func (req *Request) WithLogger(logger LogCallback) *Request
type RequestOption ¶ added in v1.1.0
func SetAccept ¶
func SetAccept(refer string) RequestOption
func SetCookie ¶ added in v1.1.0
func SetCookie(cookie string) RequestOption
func SetHeader ¶ added in v1.1.0
func SetHeader(header Header) RequestOption
func SetRefer ¶
func SetRefer(refer string) RequestOption
type ResponseBody ¶
type ResponseBody struct { Status int `json:"status"` Data any `json:"data"` Message string `json:"message"` }
func (*ResponseBody) CheckError ¶
func (res *ResponseBody) CheckError() error
type ResponseBody2 ¶ added in v1.1.0
func (*ResponseBody2) CheckError ¶ added in v1.1.0
func (res *ResponseBody2) CheckError() error
type ResponseBodyCheck ¶
type ResponseBodyCheck interface {
CheckError() error
}
func CommonResponse ¶
func CommonResponse(response interface{}) ResponseBodyCheck
func CommonResponse2 ¶ added in v1.1.0
func CommonResponse2(response interface{}) ResponseBodyCheck
Source Files ¶
Click to show internal directories.
Click to hide internal directories.