Documentation
¶
Index ¶
- Constants
- Variables
- func CloseReaderWrap(err error) error
- func DefaultHeader() http.Header
- 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 Client
- func (d *Client) AddHeader(k, v string) *Client
- func (d *Client) BaseUrl(url string) *Client
- func (d *Client) BasicAuth(authUser, authPass string) *Client
- func (d *Client) Clone() *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 http.Header) *Client
- func (d *Client) HeaderX(header httpx.Header) *Client
- func (d *Client) HttpClient(client *http.Client) *Client
- func (d *Client) HttpRequestOptions(opts ...HttpRequestOption) *Client
- func (d *Client) LogLevel(lvl LogLevel) *Client
- func (d *Client) Logger(logger AccessLog) *Client
- func (d *Client) NoProxy() *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) ReqBodyMarshal(handler func(v any) ([]byte, error)) *Client
- func (d *Client) Request(method, url string) *Request
- func (d *Client) ResetProxy() *Client
- func (d *Client) RespBodyHandler(handler func(data []byte) ([]byte, error)) *Client
- func (d *Client) RespBodyUnMarshal(handler func(data []byte, v any) 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, concurrencyNum int) error
- func (dReq *DownloadReq) Context(ctx context.Context) *DownloadReq
- 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 (dReq *DownloadReq) Header(header http.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 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) DoRaw(param any) (RawBytes, error)
- func (req *Request) DoResponse(param any) (*http.Response, error)
- func (req *Request) DoStream(param any) (io.ReadCloser, error)
- func (req *Request) Header(header http.Header) *Request
- func (req *Request) HeaderX(header httpx.Header) *Request
- type RequestOption
- type ResponseBodyCheck
- type SetRequest
- type UploadMode
- type UploadReq
- func (r *UploadReq) Boundary(boundary string) *UploadReq
- func (r *UploadReq) ChunkSize(chunkSize int64) *UploadReq
- func (r *UploadReq) ConcurrentUploadReaderChunked(reader io.ReaderAt, name string, total int64, concurrencyNum int) error
- func (r *UploadReq) Context(ctx context.Context) *UploadReq
- func (r *UploadReq) Mode(mode UploadMode) *UploadReq
- func (r *UploadReq) Upload(filepath string) error
- func (r *UploadReq) UploadMultipart(formData map[string]string, files ...*Multipart) error
- func (r *UploadReq) UploadReader(reader io.Reader, name string) error
- func (r *UploadReq) UploadReaderChunked(reader io.ReaderAt, name string, total int64) error
- func (r *UploadReq) Uploader(u *Uploader) *UploadReq
- type Uploader
Constants ¶
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 */ )
const DownloadKey = fs.DownloadKey
const RangeFormat = "bytes=%d-%d/%d"
const RangeFormat2 = "bytes=%d-%d/*"
Variables ¶
var ( DefaultHttpClient = newHttpClient(ClientTypeApi) DefaultLogLevel = LogLevelError )
var ( ErrNotFound = fmt.Errorf("not found") ErrRangeNotSatisfiable = fmt.Errorf("range not satisfiable") )
var (
ContentTypeKey = http.CanonicalHeaderKey("Content-Type")
)
var (
DefaultClient = New().DisableLog()
)
var DefaultDownloadHttpClient = newDownloadHttpClient()
var DefaultDownloader = NewDownloader()
var DefaultUploader = NewUploader()
Functions ¶
func CloseReaderWrap ¶
CloseReaderWrap closes and releases resources.
func DefaultLogger ¶
func DefaultLogger(param *AccessLogParam, err error)
DefaultLogger performs the operation.
func DownloadImage ¶
DownloadImage executes the operation.
func DownloadToDir ¶
DownloadToDir executes the operation.
func GetReaderWithHttpRequestOptions ¶
func GetReaderWithHttpRequestOptions(url string, opts ...HttpRequestOption) (io.ReadCloser, error)
GetReaderWithHttpRequestOptions returns the value.
func GetStream ¶
func GetStream(url string, param any) (io.ReadCloser, error)
GetStream returns the value.
func UserAgentChrome ¶
UserAgentChrome returns the result.
Types ¶
type AccessLog ¶
type AccessLog func(param *AccessLogParam, err error)
type AccessLogParam ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client defines a type.
func DefaultHeaderClient ¶
func DefaultHeaderClient() *Client
DefaultHeaderClient returns the result.
func (*Client) DeleteRequest ¶
DeleteRequest removes or resets state.
func (*Client) GetRequest ¶
GetRequest returns the value.
func (*Client) GetStreamX ¶
func (d *Client) GetStreamX(url string) (io.ReadCloser, error)
GetStreamX returns the value.
func (*Client) HttpClient ¶
HttpClient returns the result.
func (*Client) HttpRequestOptions ¶
func (d *Client) HttpRequestOptions(opts ...HttpRequestOption) *Client
HttpRequestOptions returns the result.
func (*Client) PostRequest ¶
PostRequest returns the result.
func (*Client) PutRequest ¶
PutRequest updates or inserts a value.
func (*Client) ReqBodyMarshal ¶ added in v1.6.6
ReqBodyMarshal returns the result.
func (*Client) ResetProxy ¶
ResetProxy removes or resets state.
func (*Client) RespBodyHandler ¶ added in v1.6.6
RespBodyHandler returns the result.
func (*Client) RespBodyUnMarshal ¶ added in v1.6.6
RespBodyUnMarshal returns the result.
func (*Client) ResponseHandler ¶
func (d *Client) ResponseHandler(handler func(response *http.Response) (retry bool, reader io.ReadCloser, err error)) *Client
ResponseHandler returns the result.
func (*Client) RetryHandler ¶
RetryHandler returns the result.
func (*Client) RetryTimes ¶
RetryTimes returns the result.
func (*Client) RetryTimesWithInterval ¶
RetryTimesWithInterval returns the result.
func (*Client) SetHttpClient ¶
func (d *Client) SetHttpClient(opt HttpClientOption) *Client
SetHttpClient updates or inserts a value.
type ClientType ¶
type ClientType uint8
const ( ClientTypeApi ClientType = iota ClientTypeDownload ClientTypeUpload )
type ContentType ¶
type ContentType uint8
const ( ContentTypeUnset ContentType = iota ContentTypeJson ContentTypeForm ContentTypeFormData ContentTypeGrpc ContentTypeGrpcWeb ContentTypeXml ContentTypeText ContentTypeBinary ContentTypeApplication ContentTypeImage ContentTypeAudio ContentTypeVideo )
func (*ContentType) Decode ¶
func (c *ContentType) Decode(contentType string)
Decode formats or converts the value.
func (ContentType) String ¶
func (c ContentType) String() string
String returns the string representation.
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
NewDownloadReq creates and returns a new instance.
func (*DownloadReq) AddHeader ¶
func (dReq *DownloadReq) AddHeader(k, v string) *DownloadReq
AddHeader updates or inserts a value.
func (*DownloadReq) ConcurrencyDownload ¶
func (dReq *DownloadReq) ConcurrencyDownload(filepath string, concurrencyNum int) error
ConcurrencyDownload performs the operation.
func (*DownloadReq) Context ¶ added in v1.11.2
func (dReq *DownloadReq) Context(ctx context.Context) *DownloadReq
Context returns the result.
func (*DownloadReq) Download ¶
func (dReq *DownloadReq) Download(filepath string) error
Download executes the operation.
func (*DownloadReq) DownloadAttachment ¶
func (dReq *DownloadReq) DownloadAttachment(dir string) error
DownloadAttachment executes the operation.
func (*DownloadReq) Downloader ¶
func (dReq *DownloadReq) Downloader(c *Downloader) *DownloadReq
Downloader executes the operation.
func (*DownloadReq) GetMode ¶
func (dReq *DownloadReq) GetMode() DownloadMode
GetMode returns the value.
func (*DownloadReq) GetReader ¶
func (dReq *DownloadReq) GetReader() (io.ReadCloser, error)
GetReader returns the value.
func (*DownloadReq) GetResponse ¶
GetResponse returns the value.
func (*DownloadReq) Header ¶
func (dReq *DownloadReq) Header(header http.Header) *DownloadReq
Header returns the result.
func (*DownloadReq) Mode ¶
func (dReq *DownloadReq) Mode(mode DownloadMode) *DownloadReq
Mode returns the result.
func (*DownloadReq) OverwriteMode ¶
func (dReq *DownloadReq) OverwriteMode() *DownloadReq
OverwriteMode returns the result.
func (*DownloadReq) SetDownloader ¶
func (dReq *DownloadReq) SetDownloader(set func(c *Downloader)) *DownloadReq
SetDownloader updates or inserts a value.
type Downloader ¶
type Downloader = Client
TODO: Range Status(206) PartialContent download
func NewDownloader ¶
func NewDownloader(options ...Option) *Downloader
NewDownloader creates and returns a new instance.
func (*Downloader) Download ¶
func (d *Downloader) Download(filepath string, r *DownloadReq) error
Download executes the operation.
func (*Downloader) DownloadAttachment ¶
func (d *Downloader) DownloadAttachment(dir string, r *DownloadReq)
DownloadAttachment executes the operation.
func (*Downloader) DownloadReq ¶
func (d *Downloader) DownloadReq(url string) *DownloadReq
DownloadReq executes the operation.
type File ¶
func (*File) ToMutilPart ¶
ToMutilPart converts the value.
type FromResponse ¶
type HttpClientOption ¶
type HttpRequestOption ¶
func AddHeader ¶
func AddHeader(k, v string) HttpRequestOption
AddHeader updates or inserts a value.
func SetAccept ¶
func SetAccept(refer string) HttpRequestOption
SetAccept updates or inserts a value.
func SetCookie ¶
func SetCookie(cookie string) HttpRequestOption
SetCookie updates or inserts a value.
func (HttpRequestOption) ToOption ¶
func (o HttpRequestOption) ToOption() Option
ToOption converts the value.
type Multipart ¶
type Multipart struct {
Name string
Value string
Filename string
Header textproto.MIMEHeader
io.Reader
}
func NewMultipart ¶
NewMultipart creates and returns a new instance.
type Request ¶
type Request struct {
Method, Url string
// contains filtered or unexported fields
}
func DefaultHeaderRequest ¶
func DefaultHeaderRequest() *Request
DefaultHeaderRequest returns the result.
func NewRequest ¶
func NewRequest(method, url string, opts ...RequestOption) *Request
NewRequest creates and returns a new instance.
func (*Request) ContentType ¶
func (req *Request) ContentType(contentType ContentType) *Request
ContentType returns the result.
func (*Request) DoResponse ¶ added in v1.11.8
DoResponse executes the operation.
func (*Request) DoStream ¶
func (req *Request) DoStream(param any) (io.ReadCloser, error)
DoStream executes the operation.
type RequestOption ¶
type RequestOption func(req *Request)
type ResponseBodyCheck ¶
type ResponseBodyCheck interface {
CheckError() error
}
type SetRequest ¶
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 ¶
NewUploadReq creates and returns a new instance.
func (*UploadReq) ConcurrentUploadReaderChunked ¶ added in v1.11.2
func (r *UploadReq) ConcurrentUploadReaderChunked(reader io.ReaderAt, name string, total int64, concurrencyNum int) error
ConcurrentUploadReaderChunked performs the operation.
func (*UploadReq) Mode ¶
func (r *UploadReq) Mode(mode UploadMode) *UploadReq
Mode returns the result.
func (*UploadReq) UploadMultipart ¶
UploadMultipart performs the operation.
func (*UploadReq) UploadReader ¶ added in v1.11.2
UploadReader performs the operation.
func (*UploadReq) UploadReaderChunked ¶ added in v1.11.2
UploadReaderChunked performs the operation.