Skip to content

Commit

Permalink
fmt code.
Browse files Browse the repository at this point in the history
  • Loading branch information
melbahja committed Aug 15, 2020
1 parent d142d32 commit 98d5912
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions got.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand Down Expand Up @@ -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,
},
}
}

0 comments on commit 98d5912

Please sign in to comment.