Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultLogger(method, url, auth string, reqBody, respBody *Body, status int, ...)
- func Delete(url string, param, response interface{}) error
- func DisableLog()
- func Download(dir, url string) error
- func DownloadFile(filepath, url string) error
- func DownloadImage(filepath, url string) error
- func Get(url string, 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 GetRandUserAgent() string
- func GetStream(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 ContentType
- type DownloadMode
- type Downloader
- func (d *Downloader) AddHeader(header, value string) *Downloader
- func (d *Downloader) ConcurrencyDownloadFile(filepath string, concurrencyNum int) error
- func (d *Downloader) ContinuationDownloadFile(filepath string) error
- func (d *Downloader) DownloadFile(filepath string) error
- func (d *Downloader) ExistsSkipMode() *Downloader
- func (d *Downloader) GetResponse() (*http.Response, error)
- func (d *Downloader) SetClient(set func(*http.Client)) *Downloader
- func (d *Downloader) SetHeader(header Header) *Downloader
- func (d *Downloader) SetRequest(set RequestOption) *Downloader
- func (d *Downloader) WithClient(c *http.Client) *Downloader
- func (d *Downloader) WithMode(mode DownloadMode) *Downloader
- func (d *Downloader) WithOptions(opts ...RequestOption) *Downloader
- func (d *Downloader) WithRange(begin, end string) *Downloader
- func (d *Downloader) WithRequest(c *http.Request) *Downloader
- func (d *Downloader) WithResponseHandler(responseHandler func(response []byte) ([]byte, error)) *Downloader
- type FromResponse
- type Header
- 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) BasicAuth(authUser, authPass string)
- func (req *Request) Client(client *http.Client) *Request
- func (req *Request) ContentType(contentType ContentType) *Request
- func (req *Request) Context(ctx context.Context) *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) DoNoParam(response interface{}) error
- func (req *Request) DoNoResponse(param interface{}) error
- func (req *Request) DoRaw(param interface{}) (RawBytes, error)
- func (req *Request) DoStream(param interface{}) (io.ReadCloser, error)
- func (req *Request) Get(url string, response interface{}) error
- func (req *Request) Header(header Header) *Request
- func (req *Request) LogLevel(lvl LogLevel) *Request
- func (req *Request) Logger(logger AccessLog) *Request
- func (req *Request) Method(method string) *Request
- func (req *Request) Post(url string, param, response interface{}) error
- func (req *Request) Proxy(url string) *Request
- func (req *Request) Put(url string, param, response interface{}) error
- func (req *Request) ResponseHandler(handler func(response *http.Response) (retry bool, data []byte, err error)) *Request
- func (req *Request) RetryHandler(handle func(*Request)) *Request
- func (req *Request) RetryTimes(retryTimes int) *Request
- func (req *Request) RetryTimesWithInterval(retryTimes int, retryInterval time.Duration) *Request
- func (req *Request) Tag(tag string) *Request
- func (req *Request) Timeout(timeout time.Duration) *Request
- func (req *Request) Url(url string) *Request
- type RequestOption
- type ResponseBody
- type ResponseBody2
- type ResponseBody3
- type ResponseBodyCheck
- 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
Variables ¶
View Source
var ( DefaultClient = newHttpClient() DefaultLogLevel = LogLevelError )
View Source
var (
ErrNotFound = fmt.Errorf("not found")
)
Functions ¶
func DefaultLogger ¶
func DisableLog ¶
func DisableLog()
func DownloadFile ¶
func DownloadImage ¶
func GetFileWithReqOption ¶
func GetFileWithReqOption(url string, opts ...RequestOption) (io.ReadCloser, error)
func GetRandUserAgent ¶
func GetRandUserAgent() string
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 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 uint8
const ( DModeForceOverwrite DownloadMode = iota DModeNotExistDownload DModeContinueDownload DModeMultipartDownload // TODO )
type Downloader ¶
type Downloader struct { Client *http.Client Request *http.Request Mode DownloadMode // 模式,0-强制覆盖,1-不存在下载,2-断续下载 ResponseHandler func(response []byte) ([]byte, error) }
TODO: Range Status(206) PartialContent 下载
func NewDownloader ¶
func NewDownloader(url string) (*Downloader, error)
func (*Downloader) AddHeader ¶
func (d *Downloader) AddHeader(header, value string) *Downloader
func (*Downloader) ConcurrencyDownloadFile ¶
func (d *Downloader) ConcurrencyDownloadFile(filepath string, concurrencyNum int) error
TODO: 利用简单任务调度实现
func (*Downloader) ContinuationDownloadFile ¶
func (d *Downloader) ContinuationDownloadFile(filepath string) error
func (*Downloader) DownloadFile ¶
func (d *Downloader) DownloadFile(filepath string) error
func (*Downloader) ExistsSkipMode ¶ added in v1.7.0
func (d *Downloader) ExistsSkipMode() *Downloader
如果文件已存在,不下载覆盖
func (*Downloader) GetResponse ¶
func (d *Downloader) GetResponse() (*http.Response, error)
func (*Downloader) SetClient ¶
func (d *Downloader) SetClient(set func(*http.Client)) *Downloader
func (*Downloader) SetHeader ¶
func (d *Downloader) SetHeader(header Header) *Downloader
func (*Downloader) SetRequest ¶
func (d *Downloader) SetRequest(set RequestOption) *Downloader
func (*Downloader) WithClient ¶
func (d *Downloader) WithClient(c *http.Client) *Downloader
func (*Downloader) WithMode ¶
func (d *Downloader) WithMode(mode DownloadMode) *Downloader
func (*Downloader) WithOptions ¶
func (d *Downloader) WithOptions(opts ...RequestOption) *Downloader
func (*Downloader) WithRange ¶
func (d *Downloader) WithRange(begin, end string) *Downloader
func (*Downloader) WithRequest ¶
func (d *Downloader) WithRequest(c *http.Request) *Downloader
func (*Downloader) WithResponseHandler ¶
func (d *Downloader) WithResponseHandler(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 {
// contains filtered or unexported fields
}
Request ...
func DefaultHeaderRequest ¶
func DefaultHeaderRequest() *Request
func NewRequest ¶
func (*Request) ContentType ¶
func (req *Request) ContentType(contentType ContentType) *Request
func (*Request) DisableLog ¶
func (*Request) DoNoResponse ¶ added in v1.5.11
func (*Request) ResponseHandler ¶
func (req *Request) ResponseHandler(handler func(response *http.Response) (retry bool, data []byte, err error)) *Request
handler 返回值:是否重试,返回数据,错误
func (*Request) RetryHandler ¶
func (*Request) RetryTimes ¶
func (*Request) RetryTimesWithInterval ¶
type RequestOption ¶
func SetAccept ¶
func SetAccept(refer string) RequestOption
func SetCookie ¶
func SetCookie(cookie string) RequestOption
func SetHeader ¶
func SetHeader(header Header) 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 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.