Documentation
¶
Index ¶
- Constants
- Variables
- func CloseReaderWrap(err error) error
- func DefaultHeader() httpx.MapHeader
- func DefaultLogger(param *AccessLogParam, err error)
- func Delete(url string, param, response interface{}) error
- 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 GetReaderWithHttpRequestOptions(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 Post(url string, param, response interface{}) error
- func Put(url string, param, response interface{}) error
- func SetProxyEnv(url string)
- func SetTag(t string)
- func UserAgentChrome(version string) string
- type AccessLog
- type AccessLogParam
- type Body
- type Client
- func (d *Client) AddHeader(k, v string) *Client
- func (d *Client) BasicAuth(authUser, authPass string) *Client
- func (d *Client) Clone() *Client
- func (d *Client) CustomReqMarshal(handler func(v any) ([]byte, error)) *Client
- func (d *Client) CustomResUnMarshal(handler func(data []byte, v any) error) *Client
- func (d *Client) Delete(url string, param, response any) error
- func (d *Client) DeleteRequest(url string) *Request
- func (d *Client) DisableLog() *Client
- func (d *Client) Do(r *Request, param, response any) error
- func (d *Client) Get(url string, param, response any) error
- func (d *Client) GetRaw(url string, param any) (RawBytes, error)
- func (d *Client) GetRawX(url string) (RawBytes, error)
- func (d *Client) GetRequest(url string) *Request
- func (d *Client) GetStream(url string, param any) (io.ReadCloser, error)
- func (d *Client) GetStreamX(url string) (io.ReadCloser, error)
- func (d *Client) GetX(url string, response any) error
- func (d *Client) Header(header httpx.Header) *Client
- func (d *Client) HttpClient(client *http.Client) *Client
- func (d *Client) HttpRequestOptions(opts ...HttpRequestOption) *Downloader
- func (d *Client) LogLevel(lvl LogLevel) *Client
- func (d *Client) Logger(logger AccessLog) *Client
- func (d *Client) Post(url string, param, response any) error
- func (d *Client) PostRequest(url string) *Request
- func (d *Client) Proxy(proxyUrl string) *Client
- func (d *Client) Put(url string, param, response any) error
- func (d *Client) PutRequest(url string) *Request
- func (d *Client) Request(method, url string) *Request
- func (d *Client) ResetProxy() *Client
- func (d *Client) RespDataHandler(handler func(data []byte) ([]byte, error)) *Client
- func (d *Client) ResponseHandler(...) *Client
- func (d *Client) RetryHandler(handle func(r *http.Request)) *Client
- func (d *Client) RetryTimes(retryTimes int) *Client
- func (d *Client) RetryTimesWithInterval(retryTimes int, retryInterval time.Duration) *Client
- func (d *Client) SetHttpClient(opt HttpClientOption) *Client
- func (d *Client) Timeout(timeout time.Duration) *Client
- type ClientType
- type ContentType
- type DownloadMode
- type DownloadReq
- func (dReq *DownloadReq) AddHeader(k, v string) *DownloadReq
- func (dReq *DownloadReq) ConcurrencyDownload(filepath string, url string, concurrencyNum int) error
- func (dReq *DownloadReq) Download(filepath string) error
- func (dReq *DownloadReq) DownloadAttachment(dir string) error
- func (dReq *DownloadReq) Downloader(c *Downloader) *DownloadReq
- func (dReq *DownloadReq) GetMode() DownloadMode
- func (dReq *DownloadReq) GetReader() (io.ReadCloser, error)
- func (dReq *DownloadReq) GetResponse(options ...func(*http.Request)) (*http.Response, error)
- func (req *DownloadReq) Header(header httpx.Header) *DownloadReq
- func (dReq *DownloadReq) Mode(mode DownloadMode) *DownloadReq
- func (dReq *DownloadReq) OverwriteMode() *DownloadReq
- func (dReq *DownloadReq) SetDownloader(set func(c *Downloader)) *DownloadReq
- type Downloader
- type File
- type FromResponse
- type HttpClientOption
- type HttpRequestOption
- type LogLevel
- type MarshalBody
- type Multipart
- type Option
- type RawBytes
- type Request
- func (req *Request) AddHeader(k, v string) *Request
- func (req *Request) Client(c *Client) *Request
- 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) Header(header httpx.Header) *Request
- type RequestOption
- type ResponseBody
- type ResponseBody2
- type ResponseBodyCheck
- type SetRequest
- type UnmarshalBody
- type UploadMode
- type UploadReq
- func (r *UploadReq) Boundary(boundary string) *UploadReq
- func (r *UploadReq) ChunkSize(chunkSize int) *UploadReq
- func (r *UploadReq) Mode(mode UploadMode) *UploadReq
- func (r *UploadReq) UploadMultipart(formData map[string]string, files ...*Multipart) error
- func (r *UploadReq) UploadMultipartChunked(formData map[string]string, file Multipart) error
- func (r *UploadReq) UploadRaw(reader io.Reader, name string) error
- func (r *UploadReq) UploadRawChunked(reader io.Reader, name string) error
- func (r *UploadReq) UploadStream(oReader io.Reader) error
- func (r *UploadReq) Uploader(u *Uploader) *UploadReq
- 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(ClientTypeApi) DefaultLogLevel = LogLevelError )
View Source
var ( ErrNotFound = fmt.Errorf("not found") ErrRangeNotSatisfiable = fmt.Errorf("range not satisfiable") )
View Source
var (
ContentTypeKey = http.CanonicalHeaderKey("Content-Type")
)
View Source
var (
DefaultClient = New().DisableLog()
)
View Source
var DefaultDownloadHttpClient = newDownloadHttpClient()
View Source
var DefaultDownloader = NewDownloader()
View Source
var DefaultUploader = NewUploader()
Functions ¶
func CloseReaderWrap ¶
func DefaultHeader ¶
func DefaultLogger ¶
func DefaultLogger(param *AccessLogParam, err error)
func DownloadImage ¶
func DownloadToDir ¶
func GetRandUserAgent ¶
func GetRandUserAgent() string
func GetReaderWithHttpRequestOptions ¶
func GetReaderWithHttpRequestOptions(url string, opts ...HttpRequestOption) (io.ReadCloser, error)
func GetStreamX ¶
func GetStreamX(url string) (io.ReadCloser, error)
func ImageOption ¶
func SetProxyEnv ¶
func SetProxyEnv(url string)
func UserAgentChrome ¶
Types ¶
type AccessLog ¶
type AccessLog func(param *AccessLogParam, err error)
type AccessLogParam ¶
type Body ¶
type Body struct {
Data []byte
ContentType ContentType
}
func NewBody ¶
func NewBody(data []byte, contentType ContentType) *Body
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client ...
func DefaultHeaderClient ¶
func DefaultHeaderClient() *Client
func (*Client) CustomReqMarshal ¶
func (*Client) CustomResUnMarshal ¶
func (*Client) DeleteRequest ¶
func (*Client) DisableLog ¶
func (*Client) GetRequest ¶
func (*Client) GetStreamX ¶
func (d *Client) GetStreamX(url string) (io.ReadCloser, error)
func (*Client) HttpRequestOptions ¶
func (d *Client) HttpRequestOptions(opts ...HttpRequestOption) *Downloader
func (*Client) PostRequest ¶
func (*Client) PutRequest ¶
func (*Client) ResetProxy ¶
func (*Client) RespDataHandler ¶
func (*Client) ResponseHandler ¶
func (d *Client) ResponseHandler(handler func(response *http.Response) (retry bool, reader io.ReadCloser, err error)) *Client
handler 返回值:是否重试,返回数据,错误
func (*Client) RetryTimes ¶
func (*Client) RetryTimesWithInterval ¶
func (*Client) SetHttpClient ¶
func (d *Client) SetHttpClient(opt HttpClientOption) *Client
type ClientType ¶
type ClientType uint8
const ( ClientTypeApi ClientType = iota ClientTypeDownload ClientType = iota ClientTypeUpload ClientType = iota )
type ContentType ¶
type ContentType uint8
const ( ContentTypeJson ContentType = iota ContentTypeForm ContentTypeFormData ContentTypeGrpc ContentTypeGrpcWeb ContentTypeXml ContentTypeText ContentTypeBinary ContentTypeApplication ContentTypeImage ContentTypeAudio ContentTypeVideo )
func (*ContentType) Decode ¶
func (c *ContentType) Decode(contentType string)
func (ContentType) String ¶
func (c ContentType) String() string
type DownloadMode ¶
type DownloadMode uint16
const ( DModeOverwrite DownloadMode = 1 << iota DModeForceContinue )
type DownloadReq ¶
type DownloadReq struct {
Url string
// contains filtered or unexported fields
}
func NewDownloadReq ¶
func NewDownloadReq(url string) *DownloadReq
func (*DownloadReq) AddHeader ¶
func (dReq *DownloadReq) AddHeader(k, v string) *DownloadReq
func (*DownloadReq) ConcurrencyDownload ¶
func (dReq *DownloadReq) ConcurrencyDownload(filepath string, url string, concurrencyNum int) error
TODO: 利用简单任务调度实现
func (*DownloadReq) Download ¶
func (dReq *DownloadReq) Download(filepath string) error
func (*DownloadReq) DownloadAttachment ¶
func (dReq *DownloadReq) DownloadAttachment(dir string) error
func (*DownloadReq) Downloader ¶
func (dReq *DownloadReq) Downloader(c *Downloader) *DownloadReq
func (*DownloadReq) GetMode ¶
func (dReq *DownloadReq) GetMode() DownloadMode
func (*DownloadReq) GetReader ¶
func (dReq *DownloadReq) GetReader() (io.ReadCloser, error)
func (*DownloadReq) GetResponse ¶
func (*DownloadReq) Header ¶
func (req *DownloadReq) Header(header httpx.Header) *DownloadReq
func (*DownloadReq) Mode ¶
func (dReq *DownloadReq) Mode(mode DownloadMode) *DownloadReq
func (*DownloadReq) OverwriteMode ¶
func (dReq *DownloadReq) OverwriteMode() *DownloadReq
如果文件已存在,强制覆盖
func (*DownloadReq) SetDownloader ¶
func (dReq *DownloadReq) SetDownloader(set func(c *Downloader)) *DownloadReq
type Downloader ¶
type Downloader = Client
TODO: Range Status(206) PartialContent 下载
func NewDownloader ¶
func NewDownloader(options ...Option) *Downloader
func (*Downloader) Download ¶
func (d *Downloader) Download(filepath string, r *DownloadReq) error
func (*Downloader) DownloadAttachment ¶
func (d *Downloader) DownloadAttachment(dir string, r *DownloadReq)
func (*Downloader) DownloadReq ¶
func (d *Downloader) DownloadReq(url string) *DownloadReq
type File ¶
func (*File) ToMutilPart ¶
type FromResponse ¶
type HttpClientOption ¶
type HttpRequestOption ¶
func AddHeader ¶
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
func (HttpRequestOption) ToOption ¶
func (o HttpRequestOption) ToOption() Option
type MarshalBody ¶
type Request ¶
type Request struct {
Method, Url string
// contains filtered or unexported fields
}
func DefaultHeaderRequest ¶
func DefaultHeaderRequest() *Request
func DeleteRequest ¶
func GetRequest ¶
func NewRequest ¶
func NewRequest(method, url string, opts ...RequestOption) *Request
func PostRequest ¶
func PutRequest ¶
func (*Request) ContentType ¶
func (req *Request) ContentType(contentType ContentType) *Request
func (*Request) DoNoResponse ¶
type RequestOption ¶
type RequestOption func(req *Request)
type ResponseBody ¶
type ResponseBody httpx.RespAnyData
func (*ResponseBody) CheckError ¶
func (res *ResponseBody) CheckError() error
type ResponseBody2 ¶
type ResponseBody2 struct {
Status int `json:"status"`
Msg string `json:"msg"`
Data any `json:"data"`
}
func (*ResponseBody2) CheckError ¶
func (res *ResponseBody2) CheckError() error
type ResponseBodyCheck ¶
type ResponseBodyCheck interface {
CheckError() error
}
func CommonResponse ¶
func CommonResponse(response interface{}) ResponseBodyCheck
func CommonResponse2 ¶
func CommonResponse2(response interface{}) ResponseBodyCheck
type SetRequest ¶
type UnmarshalBody ¶
type UploadMode ¶
type UploadMode uint16
const ( UModeNormal UploadMode = iota UModeStream UModeChunked UModeChunkedConcurrent )
type UploadReq ¶
type UploadReq struct {
Url string
// contains filtered or unexported fields
}
func NewUploadReq ¶
func (*UploadReq) Mode ¶
func (r *UploadReq) Mode(mode UploadMode) *UploadReq
func (*UploadReq) UploadMultipart ¶
func (*UploadReq) UploadMultipartChunked ¶
默认单文件
func (*UploadReq) UploadRawChunked ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.