From 98d591217511c299e192d6ce445e2b37da64ec2e Mon Sep 17 00:00:00 2001 From: Mohamed Elbahja Date: Sun, 16 Aug 2020 00:11:26 +0100 Subject: [PATCH] fmt code. --- got.go | 62 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/got.go b/got.go index 62f0f26..7c5c825 100644 --- a/got.go +++ b/got.go @@ -2,41 +2,11 @@ package got import ( "context" + "errors" "net/http" "time" - "errors" ) -// DefaulUserAgent is the default Got user agent to send http requests. -const DefaulUserAgent = "Got/1.0" - -// ErrDownloadAborted - When download is aborted by the OS before it is completed, ErrDownloadAborted will be triggered -var ErrDownloadAborted = errors.New("Operation aborted") - -// NewRequest returns a new http.Request and error if any. -func NewRequest(ctx context.Context, method, URL string) (req *http.Request, err error) { - - if req, err = http.NewRequestWithContext(ctx, method, URL, nil); err != nil { - return - } - - req.Header.Set("User-Agent", DefaulUserAgent) - return -} - -// GetDefaultClient returns Got default http.Client -func GetDefaultClient() *http.Client { - - return &http.Client{ - Transport: &http.Transport{ - MaxIdleConns: 10, - IdleConnTimeout: 30 * time.Second, - TLSHandshakeTimeout: 5 * time.Second, - Proxy: http.ProxyFromEnvironment, - }, - } -} - // Got holds got download config. type Got struct { ProgressFunc @@ -46,6 +16,12 @@ type Got struct { ctx context.Context } +// DefaulUserAgent is the default Got user agent to send http requests. +const DefaulUserAgent = "Got/1.0" + +// ErrDownloadAborted - When download is aborted by the OS before it is completed, ErrDownloadAborted will be triggered +var ErrDownloadAborted = errors.New("Operation aborted") + // Download creates *Download item and runs it. func (g Got) Download(URL, dest string) error { @@ -88,3 +64,27 @@ func NewWithContext(ctx context.Context) *Got { Client: GetDefaultClient(), } } + +// NewRequest returns a new http.Request and error if any. +func NewRequest(ctx context.Context, method, URL string) (req *http.Request, err error) { + + if req, err = http.NewRequestWithContext(ctx, method, URL, nil); err != nil { + return + } + + req.Header.Set("User-Agent", DefaulUserAgent) + return +} + +// GetDefaultClient returns Got default http.Client +func GetDefaultClient() *http.Client { + + return &http.Client{ + Transport: &http.Transport{ + MaxIdleConns: 10, + IdleConnTimeout: 30 * time.Second, + TLSHandshakeTimeout: 5 * time.Second, + Proxy: http.ProxyFromEnvironment, + }, + } +}