Documentation ¶
Index ¶
- Constants
- Variables
- 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 GetFile(url string) (io.ReadCloser, error)
- func GetFileWithReqOption(url string, opts ...RequestOption) (io.ReadCloser, error)
- func GetImage(url string) (io.ReadCloser, error)
- func GetNP(url string, response any) error
- func GetRandUserAgent() string
- func GetStream(url string, param any) (io.ReadCloser, error)
- func GetStreamNP(url string) (io.ReadCloser, 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 (req *Client) AddHeader(k, v string) *Client
- func (req *Client) BasicAuth(authUser, authPass string) *Client
- func (req *Client) Clone() *Client
- func (req *Client) ContentType(contentType ContentType) *Client
- func (req *Client) Context(ctx context.Context) *Client
- func (req *Client) Delete(url string, param, response interface{}) error
- func (req *Client) DisableLog() *Client
- func (req *Client) Do(method, url string, param, response interface{}) error
- func (req *Client) DoEmpty(method, url string) error
- func (req *Client) DoNoParam(method, url string, response interface{}) error
- func (req *Client) DoNoResponse(method, url string, param interface{}) error
- func (req *Client) DoRaw(method, url string, param interface{}) (RawBytes, error)
- func (req *Client) DoStream(method, url string, param interface{}) (io.ReadCloser, error)
- func (req *Client) Get(url string, param, response interface{}) error
- func (req *Client) GetNP(url string, response interface{}) error
- func (req *Client) Header(header http.Header) *Client
- func (req *Client) HttpClient(client *http.Client) *Client
- func (req *Client) LogLevel(lvl LogLevel) *Client
- func (req *Client) Logger(logger AccessLog) *Client
- func (req *Client) ParseTag(tag string) *Client
- func (req *Client) Post(url string, param, response interface{}) error
- func (req *Client) Proxy(url string) *Client
- func (req *Client) Put(url string, param, response interface{}) error
- func (req *Client) Request(method, url string) *Request
- func (req *Client) ResponseHandler(handler func(response *http.Response) (retry bool, data []byte, err error)) *Client
- func (req *Client) RetryHandler(handle func(*Client)) *Client
- func (req *Client) RetryTimes(retryTimes int) *Client
- func (req *Client) RetryTimesWithInterval(retryTimes int, retryInterval time.Duration) *Client
- func (req *Client) Timeout(timeout time.Duration) *Client
- type ClientOption
- type ContentType
- type DownloadMode
- type Downloader
- func (d *Downloader) AddHeader(header, value string) *Downloader
- func (d *Downloader) ConcurrencyDownload(filepath string, concurrencyNum int) error
- func (d *Downloader) ContinuationDownload(filepath, url string) error
- func (d *Downloader) Download(filepath, url string) error
- func (d *Downloader) ExistsSkipMode() *Downloader
- func (d *Downloader) GetMode() DownloadMode
- func (d *Downloader) GetResponse(url string) (*http.Response, error)
- func (d *Downloader) Header(header http.Header) *Downloader
- func (d *Downloader) HttpClient(c *http.Client) *Downloader
- func (d *Downloader) Mode(mode DownloadMode) *Downloader
- func (d *Downloader) Options(opts ...RequestOption) *Downloader
- func (d *Downloader) Range(begin, end string) *Downloader
- func (d *Downloader) ResponseHandler(responseHandler func(response []byte) ([]byte, error)) *Downloader
- type FromResponse
- type LogLevel
- type Logger
- type MarshalBody
- type MarshalHeader
- type MarshalQuery
- type Option
- type RawBytes
- type Request
- func (req *Request) Delete(param, response interface{}) error
- func (req *Request) Do(param, response interface{}) error
- func (req *Request) DoEmpty() error
- func (req *Request) DoNoParam(response interface{}) error
- func (req *Request) DoNoResponse(param interface{}) error
- func (req *Request) DoRaw(param interface{}) (RawBytes, error)
- func (req *Request) DoStream(method, url string, param interface{}) (io.ReadCloser, error)
- func (req *Request) Get(param, response interface{}) error
- func (req *Request) Post(param, response interface{}) error
- func (req *Request) Put(param, response interface{}) error
- type RequestOption
- 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 ( DModeOverwrite DownloadMode = iota DModeNotExist DModeContinue = DModeNotExist << 1 DModeMultipartDownload = DModeNotExist << 2 // TODO )
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
Variables ¶
View Source
var ( DefaultHttpClient = newHttpClient() DefaultLogLevel = LogLevelError )
View Source
var (
ErrNotFound = fmt.Errorf("not found")
)
Functions ¶
func DefaultHeader ¶
func DefaultLogger ¶
func DisableLog ¶
func DisableLog()
func DownloadImage ¶
func DownloadToDir ¶ added in v1.5.11
func GetFileWithReqOption ¶
func GetFileWithReqOption(url string, opts ...RequestOption) (io.ReadCloser, error)
func GetRandUserAgent ¶
func GetRandUserAgent() string
func GetStreamNP ¶ added in v1.14.0
func GetStreamNP(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) ContentType ¶ added in v1.14.0
func (req *Client) ContentType(contentType ContentType) *Client
func (*Client) DisableLog ¶ added in v1.5.11
func (*Client) Do ¶ added in v1.5.11
Do create a HTTP request param: 请求参数 目前只支持编码为json 或 url-encoded
func (*Client) DoNoResponse ¶ added in v1.14.0
func (*Client) DoStream ¶ added in v1.14.0
func (req *Client) DoStream(method, url string, param interface{}) (io.ReadCloser, error)
func (*Client) HttpClient ¶ added in v1.5.11
func (*Client) ResponseHandler ¶ added in v1.5.11
func (req *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
type ClientOption ¶ added in v1.14.0
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
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
TODO: Range Status(206) PartialContent 下载
func NewDownloader ¶
func NewDownloader() *Downloader
func (*Downloader) AddHeader ¶
func (d *Downloader) AddHeader(header, value string) *Downloader
func (*Downloader) ConcurrencyDownload ¶ added in v1.14.0
func (d *Downloader) ConcurrencyDownload(filepath string, concurrencyNum int) error
TODO: 利用简单任务调度实现
func (*Downloader) ContinuationDownload ¶ added in v1.14.0
func (d *Downloader) ContinuationDownload(filepath, url string) error
func (*Downloader) Download ¶ added in v1.5.11
func (d *Downloader) Download(filepath, url string) error
func (*Downloader) ExistsSkipMode ¶ added in v1.7.0
func (d *Downloader) ExistsSkipMode() *Downloader
如果文件已存在,不下载覆盖
func (*Downloader) GetMode ¶ added in v1.14.0
func (d *Downloader) GetMode() DownloadMode
func (*Downloader) GetResponse ¶
func (d *Downloader) GetResponse(url string) (*http.Response, error)
func (*Downloader) Header ¶ added in v1.5.11
func (d *Downloader) Header(header http.Header) *Downloader
func (*Downloader) HttpClient ¶ added in v1.5.11
func (d *Downloader) HttpClient(c *http.Client) *Downloader
func (*Downloader) Mode ¶
func (d *Downloader) Mode(mode DownloadMode) *Downloader
func (*Downloader) Options ¶ added in v1.5.11
func (d *Downloader) Options(opts ...RequestOption) *Downloader
func (*Downloader) Range ¶ added in v1.14.0
func (d *Downloader) Range(begin, end string) *Downloader
func (*Downloader) ResponseHandler ¶
func (d *Downloader) ResponseHandler(responseHandler func(response []byte) ([]byte, error)) *Downloader
type FromResponse ¶ added in v1.5.11
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 { *Client // contains filtered or unexported fields }
func DefaultHeaderRequest ¶
func DefaultHeaderRequest() *Request
func NewRequest ¶
func (*Request) DoNoResponse ¶ added in v1.5.11
type RequestOption ¶
func AddHeader ¶ added in v1.5.11
func AddHeader(k, v string) RequestOption
func SetAccept ¶
func SetAccept(refer string) RequestOption
func SetCookie ¶
func SetCookie(cookie string) RequestOption
func SetRefer ¶
func SetRefer(refer string) RequestOption
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.