Documentation ¶
Index ¶
- Constants
- Variables
- func Dial(addr string) (net.Conn, error)
- func DialDualStack(addr string) (net.Conn, error)
- func DialDualStackTimeout(addr string, timeout time.Duration) (net.Conn, error)
- func DialTimeout(addr string, timeout time.Duration) (net.Conn, error)
- func GetLength(url string, client *Client) (int, error)
- func NewResolver(cl *gnet.Client, dialer *GNetDialer) *net.Resolver
- func ProxyDialer(proxy string, timeout time.Duration) fasthttp.DialFunc
- func ReleaseRequest(req *Request)
- func ReleaseResponse(response *Response)
- type Addr
- type Buffer
- type CheckSum
- type Client
- type Config
- type DialerOptions
- type DownloadedFile
- type File
- type FileNameError
- type GNetDialer
- func (d *GNetDialer) Dial(addr string) (net.Conn, error)
- func (d *GNetDialer) DialContext(ctx context.Context, network, addr string) (net.Conn, error)
- func (d *GNetDialer) DialDualStack(addr string) (net.Conn, error)
- func (d *GNetDialer) DialDualStackTimeout(addr string, timeout time.Duration) (net.Conn, error)
- func (d *GNetDialer) DialTimeout(addr string, timeout time.Duration) (net.Conn, error)
- type ProxyFunc
- type Request
- type Response
- type SumError
- type SumType
- type ToDownload
Constants ¶
const DefaultDNSCacheDuration = time.Minute
const DefaultDialTimeout = 3 * time.Second
Variables ¶
var DefaultClient = NewClient()
var DefaultOptions = &DialerOptions{ Conn: 1000, LocalAddr: nil, DNSCacheDuration: DefaultDNSCacheDuration, }
var ErrDialTimeout = errors.New("dialing to the given TCP address timed out")
ErrDialTimeout is returned when TCP dialing is timed out.
Functions ¶
func DialDualStack ¶ added in v0.5.0
DialDualStack dials the given TCP addr using both tcp4 and tcp6.
This function has the following additional features comparing to net.Dial:
- It reduces load on DNS resolver by caching resolved TCP addressed for DNSCacheDuration.
- It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.
- It returns ErrDialTimeout if connection cannot be established during DefaultDialTimeout seconds. Use DialDualStackTimeout for custom dial timeout.
This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.
For instance, per-host counters and/or limits may be implemented by such wrappers.
The addr passed to the function must contain port. Example addr values:
- foobar.baz:443
- foo.bar:80
- aaa.com:8080
func DialDualStackTimeout ¶ added in v0.5.0
DialDualStackTimeout dials the given TCP addr using both tcp4 and tcp6 using the given timeout.
This function has the following additional features comparing to net.Dial:
- It reduces load on DNS resolver by caching resolved TCP addressed for DNSCacheDuration.
- It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.
This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.
For instance, per-host counters and/or limits may be implemented by such wrappers.
The addr passed to the function must contain port. Example addr values:
- foobar.baz:443
- foo.bar:80
- aaa.com:8080
func DialTimeout ¶ added in v0.5.0
func NewResolver ¶ added in v0.5.7
func NewResolver(cl *gnet.Client, dialer *GNetDialer) *net.Resolver
func ProxyDialer ¶ added in v0.5.0
func ReleaseRequest ¶ added in v0.5.7
func ReleaseRequest(req *Request)
func ReleaseResponse ¶ added in v0.5.2
func ReleaseResponse(response *Response)
Types ¶
type Buffer ¶ added in v0.5.0
type Buffer struct { Chunks chunk.CollectedChunks Buf []byte }
type DialerOptions ¶ added in v0.5.0
type DownloadedFile ¶ added in v0.5.0
type DownloadedFile struct {
Url, FileName, Path string
Data *Buffer
// contains filtered or unexported fields
}
func (*DownloadedFile) Save ¶ added in v0.5.0
func (c *DownloadedFile) Save(path string) error
func (*DownloadedFile) Verify ¶ added in v0.5.0
func (c *DownloadedFile) Verify() error
type File ¶
type File struct { Url string FileName string Sha string Client *Client Length int Chunks chunk.Chunks // contains filtered or unexported fields }
func (*File) Download ¶
func (c *File) Download(workers, threads int, progress bool) (*DownloadedFile, error)
func (*File) DownloadChunk ¶
func (c *File) DownloadChunk(chunk *chunk.SingleChunk) (*chunk.SingleChunk, error)
func (*File) DownloadWithProgress ¶
func (c *File) DownloadWithProgress(workers, threads int) (*DownloadedFile, error)
func (*File) GetFilename ¶
type FileNameError ¶
type FileNameError string
func (*FileNameError) Error ¶
func (e *FileNameError) Error() string
type GNetDialer ¶ added in v0.5.0
type GNetDialer struct { Concurrency int LocalAddr *net.TCPAddr Resolver *net.Resolver DNSCacheDuration time.Duration // contains filtered or unexported fields }
func NewDialer ¶ added in v0.5.0
func NewDialer(opts *DialerOptions, GNetOpts ...gnet.Option) (*GNetDialer, error)
func (*GNetDialer) Dial ¶ added in v0.5.0
func (d *GNetDialer) Dial(addr string) (net.Conn, error)
Dial dials the given TCP addr using tcp4.
This function has the following additional features comparing to net.Dial:
- It reduces load on DNS resolver by caching resolved TCP addressed for DNSCacheDuration.
- It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.
- It returns ErrDialTimeout if connection cannot be established during DefaultDialTimeout seconds. Use DialTimeout for customizing dial timeout.
This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.
For instance, per-host counters and/or limits may be implemented by such wrappers.
The addr passed to the function must contain port. Example addr values:
- foobar.baz:443
- foo.bar:80
- aaa.com:8080
func (*GNetDialer) DialContext ¶ added in v0.5.0
func (*GNetDialer) DialDualStack ¶ added in v0.5.0
func (d *GNetDialer) DialDualStack(addr string) (net.Conn, error)
DialDualStack dials the given TCP addr using both tcp4 and tcp6.
This function has the following additional features comparing to net.Dial:
- It reduces load on DNS resolver by caching resolved TCP addressed for DNSCacheDuration.
- It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.
- It returns ErrDialTimeout if connection cannot be established during DefaultDialTimeout seconds. Use DialDualStackTimeout for custom dial timeout.
This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.
For instance, per-host counters and/or limits may be implemented by such wrappers.
The addr passed to the function must contain port. Example addr values:
- foobar.baz:443
- foo.bar:80
- aaa.com:8080
func (*GNetDialer) DialDualStackTimeout ¶ added in v0.5.0
DialDualStackTimeout dials the given TCP addr using both tcp4 and tcp6 using the given timeout.
This function has the following additional features comparing to net.Dial:
- It reduces load on DNS resolver by caching resolved TCP addressed for DNSCacheDuration.
- It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.
This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.
For instance, per-host counters and/or limits may be implemented by such wrappers.
The addr passed to the function must contain port. Example addr values:
- foobar.baz:443
- foo.bar:80
- aaa.com:8080
func (*GNetDialer) DialTimeout ¶ added in v0.5.0
DialTimeout dials the given TCP addr using tcp4 using the given timeout.
This function has the following additional features comparing to net.Dial:
- It reduces load on DNS resolver by caching resolved TCP addressed for DNSCacheDuration.
- It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.
This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.
For instance, per-host counters and/or limits may be implemented by such wrappers.
The addr passed to the function must contain port. Example addr values:
- foobar.baz:443
- foo.bar:80
- aaa.com:8080
type Request ¶ added in v0.5.7
func AcquireRequest ¶ added in v0.5.7
func AcquireRequest() *Request
type Response ¶ added in v0.5.0
func AcquireResponse ¶ added in v0.5.2
func AcquireResponse() *Response
type ToDownload ¶ added in v0.5.0
type ToDownload struct { Url string FileName string Length int Chunks chunk.CollectedChunks // contains filtered or unexported fields }