Documentation ¶
Index ¶
- Constants
- Variables
- func CloseReaderWarp(err error) error
- func DefaultHeader() http.Header
- func DefaultLogger(method, url, auth string, reqBody, respBody *Body, status int, ...)
- func Delete(url string, param, response interface{}) error
- func DisableLog()
- func Download(filepath, url string) error
- func DownloadImage(filepath, url string) error
- func DownloadToDir(dir, url string) error
- func Get(url string, param, response any) error
- func GetImage(url string) (io.ReadCloser, error)
- func GetRandUserAgent() string
- func GetReader(url string) (io.ReadCloser, error)
- func GetReaderWithReqOption(url string, opts ...HttpRequestOption) (io.ReadCloser, error)
- func GetStream(url string, param any) (io.ReadCloser, error)
- func GetStreamX(url string) (io.ReadCloser, error)
- func GetX(url string, response any) error
- func ImageOption(req *http.Request)
- func NewReplaceHttpRequest(r *http.Request) *replaceHttpRequest
- func Post(url string, param, response interface{}) error
- func Put(url string, param, response interface{}) error
- func ReplaceHttpRequest(r *http.Request, url, method string, body io.ReadCloser) *http.Request
- func ResetProxy()
- func SetAccessLog(log AccessLog)
- func SetHttpClient(client *http.Client)
- func SetProxy(url string)
- func SetProxyEnv(url string)
- func SetTag(t string)
- func SetTimeout(timeout time.Duration)
- func UserAgentChrome(version string) string
- type AccessLog
- type Body
- type Client
- func (c *Client) AddHeader(k, v string) *Client
- func (c *Client) BasicAuth(authUser, authPass string) *Client
- func (c *Client) Clone() *Client
- func (c *Client) Delete(url string, param, response any) error
- func (c *Client) DeleteRequest(url string) *Request
- func (c *Client) DisableLog() *Client
- func (c *Client) Do(r *Request, param, response any) error
- func (c *Client) Get(url string, param, response any) error
- func (c *Client) GetRequest(url string) *Request
- func (c *Client) GetStream(url string, param any) (io.ReadCloser, error)
- func (c *Client) GetStreamX(url string) (io.ReadCloser, error)
- func (c *Client) GetX(url string, response any) error
- func (c *Client) Header(header http.Header) *Client
- func (c *Client) HttpClient(client *http.Client) *Client
- func (c *Client) LogLevel(lvl LogLevel) *Client
- func (c *Client) Logger(logger AccessLog) *Client
- func (c *Client) ParseTag(tag string) *Client
- func (c *Client) Post(url string, param, response any) error
- func (c *Client) PostRequest(url string) *Request
- func (c *Client) Proxy(proxyUrl string) *Client
- func (c *Client) Put(url string, param, response any) error
- func (c *Client) PutRequest(url string) *Request
- func (c *Client) Request(method, url string) *Request
- func (c *Client) RequestDo(param, response any) error
- func (c *Client) ResDataHandler(handler func(response []byte) ([]byte, error)) *Client
- func (c *Client) ResponseHandler(handler func(response *http.Response) (retry bool, data []byte, err error)) *Client
- func (c *Client) RetryHandler(handle func(*Client)) *Client
- func (c *Client) RetryTimes(retryTimes int) *Client
- func (c *Client) RetryTimesWithInterval(retryTimes int, retryInterval time.Duration) *Client
- func (c *Client) SetHttpClient(opt HttpClientOption) *Client
- func (c *Client) Timeout(timeout time.Duration) *Client
- type ContentType
- type DownloadMode
- type DownloadReq
- func (req *DownloadReq) AddHeader(k, v string) *DownloadReq
- func (c *DownloadReq) ConcurrencyDownload(filepath string, url string, concurrencyNum int) error
- func (c *DownloadReq) ContinuationDownload(filepath string) error
- func (c *DownloadReq) Download(filepath string) error
- func (req *DownloadReq) Downloader() *Downloader
- func (c *DownloadReq) GetMode() DownloadMode
- func (c *DownloadReq) GetReader() (io.ReadCloser, error)
- func (c *DownloadReq) GetResponse() (*http.Response, error)
- func (c *DownloadReq) Mode(mode DownloadMode) *DownloadReq
- func (c *DownloadReq) OverwriteMode() *DownloadReq
- func (req *DownloadReq) SetDownloader(set func(c *Downloader)) *DownloadReq
- func (req *DownloadReq) WithDownloader(c *Downloader) *DownloadReq
- type Downloader
- func (c *Downloader) AddHeader(header, value string) *Downloader
- func (c *Downloader) BasicAuth(authUser, authPass string) *Downloader
- func (c *Downloader) Clone() *Downloader
- func (c *Downloader) Download(filepath string, r *DownloadReq) error
- func (c *Downloader) DownloadReq(url string) *DownloadReq
- func (c *Downloader) GetReader(r *DownloadReq) (io.ReadCloser, error)
- func (c *Downloader) GetResponse(r *DownloadReq) (*http.Response, error)
- func (c *Downloader) Header(header http.Header) *Downloader
- func (c *Downloader) HttpClient(client *http.Client) *Downloader
- func (c *Downloader) Options(opts ...HttpRequestOption) *Downloader
- func (c *Downloader) Proxy(proxyUrl string) *Downloader
- func (c *Downloader) ReqDownload(filepath string) error
- func (c *Downloader) ResDataHandler(handler func(response []byte) ([]byte, error)) *Downloader
- func (c *Downloader) ResponseHandler(handler func(response *http.Response) (retry bool, data []byte, err error)) *Downloader
- func (c *Downloader) SetHttpClient(opt HttpClientOption) *Downloader
- func (c *Downloader) Timeout(timeout time.Duration) *Downloader
- type FromResponse
- type HttpClientOption
- type HttpRequestOption
- type LogLevel
- type Logger
- type MarshalBody
- type MarshalHeader
- type MarshalQuery
- type Option
- type RawBytes
- type Request
- func (req *Request) AddHeader(k, v string) *Request
- func (req *Request) Client() *Client
- func (req *Request) ContentType(contentType ContentType) *Request
- func (req *Request) Context(ctx context.Context) *Request
- func (req *Request) Do(param, response any) error
- func (req *Request) DoEmpty() error
- func (req *Request) DoNoParam(response any) error
- func (req *Request) DoNoResponse(param any) error
- func (req *Request) DoRaw(param any) (RawBytes, error)
- func (req *Request) DoStream(param any) (io.ReadCloser, error)
- func (req *Request) SetClient(set func(c *Client)) *Request
- func (req *Request) WithClient(c *Client) *Request
- type ResponseBody
- type ResponseBody2
- type ResponseBody3
- type ResponseBodyCheck
- type ResponseHandler
- type SetRequest
- type UnmarshalBody
- type UnmarshalHeader
- type UnmarshalQuery
- type UploadMode
- type Uploader
Constants ¶
View Source
const ( UserAgent1 = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" UserAgentChrome95 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36" UserAgentChrome117 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" UserAgentIphone = "" /* 139-byte string literal not displayed */ )
View Source
const DownloadKey = fs.DownloadKey
View Source
const RangeFormat = "bytes=%d-%d/%d"
View Source
const RangeFormat2 = "bytes=%d-%d/*"
Variables ¶
View Source
var ( DefaultHttpClient = newHttpClient() DefaultLogLevel = LogLevelError )
View Source
var ( ErrNotFound = fmt.Errorf("not found") ErrRangeNotSatisfiable = fmt.Errorf("range not satisfiable") )
View Source
var DefaultClient = New()
View Source
var DefaultDownloadHttpClient = newDownloadHttpClient()
View Source
var DefaultDownloader = NewDownloader()
Functions ¶
func CloseReaderWarp ¶ added in v1.5.11
func DefaultHeader ¶
func DefaultLogger ¶
func DisableLog ¶
func DisableLog()
func DownloadImage ¶
func DownloadToDir ¶ added in v1.5.11
func GetRandUserAgent ¶
func GetRandUserAgent() string
func GetReaderWithReqOption ¶ added in v1.5.11
func GetReaderWithReqOption(url string, opts ...HttpRequestOption) (io.ReadCloser, error)
func GetStreamX ¶ added in v1.5.11
func GetStreamX(url string) (io.ReadCloser, error)
func ImageOption ¶
func NewReplaceHttpRequest ¶
func ReplaceHttpRequest ¶
func ResetProxy ¶
func ResetProxy()
func SetAccessLog ¶ added in v1.5.11
func SetAccessLog(log AccessLog)
func SetHttpClient ¶ added in v1.5.11
func SetProxyEnv ¶
func SetProxyEnv(url string)
func SetTimeout ¶
func UserAgentChrome ¶
Types ¶
type Body ¶
type Body struct { Data []byte ContentType ContentType }
func NewBody ¶
func NewBody(data []byte, contentType ContentType) *Body
func (*Body) IsProtobuf ¶
type Client ¶ added in v1.5.11
type Client struct {
// contains filtered or unexported fields
}
Client ...
func DefaultHeaderClient ¶ added in v1.5.11
func DefaultHeaderClient() *Client
func (*Client) DeleteRequest ¶ added in v1.5.11
func (*Client) DisableLog ¶ added in v1.5.11
func (*Client) GetRequest ¶ added in v1.5.11
func (*Client) GetStreamX ¶ added in v1.5.11
func (c *Client) GetStreamX(url string) (io.ReadCloser, error)
func (*Client) HttpClient ¶ added in v1.5.11
func (*Client) PostRequest ¶ added in v1.5.11
func (*Client) PutRequest ¶ added in v1.5.11
func (*Client) ResDataHandler ¶ added in v1.5.11
func (*Client) ResponseHandler ¶ added in v1.5.11
func (c *Client) ResponseHandler(handler func(response *http.Response) (retry bool, data []byte, err error)) *Client
handler 返回值:是否重试,返回数据,错误
func (*Client) RetryHandler ¶ added in v1.5.11
func (*Client) RetryTimes ¶ added in v1.5.11
func (*Client) RetryTimesWithInterval ¶ added in v1.5.11
func (*Client) SetHttpClient ¶ added in v1.5.11
func (c *Client) SetHttpClient(opt HttpClientOption) *Client
type ContentType ¶
type ContentType uint8
const ( ContentTypeJson ContentType = iota ContentTypeForm ContentTypeFormData ContentTypeGrpc ContentTypeGrpcWeb ContentTypeXml ContentTypeText ContentTypeBinary ContentTypeApplication ContentTypeImage ContentTypeAudio ContentTypeVideo )
func (*ContentType) Decode ¶ added in v1.5.11
func (c *ContentType) Decode(contentType string)
func (ContentType) String ¶ added in v1.5.11
func (c ContentType) String() string
type DownloadMode ¶ added in v1.5.11
type DownloadMode uint16
const ( DModeOverwrite DownloadMode = 1 << iota DModeContinue DModeMultipart // TODO 分块下载后合并 DModeMultiThread // TODO 暂时没找到并发写文件的方法,可以并发下载,顺序写入 )
type DownloadReq ¶ added in v1.5.11
type DownloadReq struct { Url string // contains filtered or unexported fields }
func NewDownloadReq ¶ added in v1.5.11
func NewDownloadReq(url string) *DownloadReq
func (*DownloadReq) AddHeader ¶ added in v1.5.11
func (req *DownloadReq) AddHeader(k, v string) *DownloadReq
func (*DownloadReq) ConcurrencyDownload ¶ added in v1.5.11
func (c *DownloadReq) ConcurrencyDownload(filepath string, url string, concurrencyNum int) error
TODO: 利用简单任务调度实现
func (*DownloadReq) ContinuationDownload ¶ added in v1.5.11
func (c *DownloadReq) ContinuationDownload(filepath string) error
func (*DownloadReq) Download ¶ added in v1.5.11
func (c *DownloadReq) Download(filepath string) error
func (*DownloadReq) Downloader ¶ added in v1.5.11
func (req *DownloadReq) Downloader() *Downloader
func (*DownloadReq) GetMode ¶ added in v1.5.11
func (c *DownloadReq) GetMode() DownloadMode
func (*DownloadReq) GetReader ¶ added in v1.5.11
func (c *DownloadReq) GetReader() (io.ReadCloser, error)
func (*DownloadReq) GetResponse ¶ added in v1.5.11
func (c *DownloadReq) GetResponse() (*http.Response, error)
func (*DownloadReq) Mode ¶ added in v1.5.11
func (c *DownloadReq) Mode(mode DownloadMode) *DownloadReq
func (*DownloadReq) OverwriteMode ¶ added in v1.5.11
func (c *DownloadReq) OverwriteMode() *DownloadReq
如果文件已存在,强制覆盖
func (*DownloadReq) SetDownloader ¶ added in v1.5.11
func (req *DownloadReq) SetDownloader(set func(c *Downloader)) *DownloadReq
func (*DownloadReq) WithDownloader ¶ added in v1.5.11
func (req *DownloadReq) WithDownloader(c *Downloader) *DownloadReq
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
TODO: Range Status(206) PartialContent 下载
func NewDownloader ¶
func NewDownloader() *Downloader
func (*Downloader) AddHeader ¶
func (c *Downloader) AddHeader(header, value string) *Downloader
func (*Downloader) BasicAuth ¶ added in v1.5.11
func (c *Downloader) BasicAuth(authUser, authPass string) *Downloader
func (*Downloader) Clone ¶ added in v1.5.11
func (c *Downloader) Clone() *Downloader
func (*Downloader) Download ¶ added in v1.5.11
func (c *Downloader) Download(filepath string, r *DownloadReq) error
func (*Downloader) DownloadReq ¶ added in v1.5.11
func (c *Downloader) DownloadReq(url string) *DownloadReq
func (*Downloader) GetReader ¶ added in v1.5.11
func (c *Downloader) GetReader(r *DownloadReq) (io.ReadCloser, error)
func (*Downloader) GetResponse ¶
func (c *Downloader) GetResponse(r *DownloadReq) (*http.Response, error)
func (*Downloader) Header ¶ added in v1.5.11
func (c *Downloader) Header(header http.Header) *Downloader
func (*Downloader) HttpClient ¶ added in v1.5.11
func (c *Downloader) HttpClient(client *http.Client) *Downloader
func (*Downloader) Options ¶ added in v1.5.11
func (c *Downloader) Options(opts ...HttpRequestOption) *Downloader
func (*Downloader) Proxy ¶ added in v1.5.11
func (c *Downloader) Proxy(proxyUrl string) *Downloader
func (*Downloader) ReqDownload ¶ added in v1.5.11
func (c *Downloader) ReqDownload(filepath string) error
func (*Downloader) ResDataHandler ¶ added in v1.5.11
func (c *Downloader) ResDataHandler(handler func(response []byte) ([]byte, error)) *Downloader
func (*Downloader) ResponseHandler ¶
func (c *Downloader) ResponseHandler(handler func(response *http.Response) (retry bool, data []byte, err error)) *Downloader
func (*Downloader) SetHttpClient ¶ added in v1.5.11
func (c *Downloader) SetHttpClient(opt HttpClientOption) *Downloader
func (*Downloader) Timeout ¶ added in v1.5.11
func (c *Downloader) Timeout(timeout time.Duration) *Downloader
type FromResponse ¶ added in v1.5.11
type HttpClientOption ¶ added in v1.5.11
type HttpRequestOption ¶ added in v1.5.11
func AddHeader ¶ added in v1.5.11
func AddHeader(k, v string) HttpRequestOption
func SetAccept ¶
func SetAccept(refer string) HttpRequestOption
func SetCookie ¶
func SetCookie(cookie string) HttpRequestOption
func SetRefer ¶
func SetRefer(refer string) HttpRequestOption
type MarshalBody ¶ added in v1.5.11
type MarshalHeader ¶ added in v1.5.11
type MarshalQuery ¶ added in v1.5.11
type Request ¶
type Request struct {
Method, Url string
// contains filtered or unexported fields
}
func DefaultHeaderRequest ¶
func DefaultHeaderRequest() *Request
func DeleteRequest ¶ added in v1.5.11
func GetRequest ¶ added in v1.5.11
func NewRequest ¶
func PostRequest ¶ added in v1.5.11
func PutRequest ¶ added in v1.5.11
func (*Request) ContentType ¶
func (req *Request) ContentType(contentType ContentType) *Request
func (*Request) DoNoResponse ¶ added in v1.5.11
func (*Request) WithClient ¶
type ResponseBody ¶
type ResponseBody httpi.ResAnyData
func (*ResponseBody) CheckError ¶
func (res *ResponseBody) CheckError() error
type ResponseBody2 ¶
func (*ResponseBody2) CheckError ¶
func (res *ResponseBody2) CheckError() error
type ResponseBody3 ¶ added in v1.5.11
type ResponseBody3 struct { Status int `json:"status"` Data any `json:"data"` Message string `json:"message"` }
func (*ResponseBody3) CheckError ¶ added in v1.5.11
func (res *ResponseBody3) CheckError() error
type ResponseBodyCheck ¶
type ResponseBodyCheck interface {
CheckError() error
}
func CommonResponse ¶
func CommonResponse(response interface{}) ResponseBodyCheck
func CommonResponse2 ¶
func CommonResponse2(response interface{}) ResponseBodyCheck
func CommonResponse3 ¶ added in v1.5.11
func CommonResponse3(response interface{}) ResponseBodyCheck
type ResponseHandler ¶ added in v1.5.11
type SetRequest ¶ added in v1.5.11
type UnmarshalBody ¶ added in v1.5.11
type UnmarshalHeader ¶ added in v1.5.11
type UnmarshalQuery ¶ added in v1.5.11
type UploadMode ¶ added in v1.5.11
type UploadMode uint8
TODO
const ( UModeNormal UploadMode = iota UModeChunk UModeStream )
Source Files ¶
Click to show internal directories.
Click to hide internal directories.