-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.go
42 lines (30 loc) · 784 Bytes
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"io"
"net/http"
"net/url"
"github.com/pkg/errors"
)
func newRequest(method string, endpoint string, body io.Reader) (*http.Request, error) {
requestURL, err := url.Parse(endpoint)
if err != nil {
return nil, errors.Wrap(err, "Parse endpoint ERROR:")
}
return http.NewRequest(method, requestURL.String(), body)
}
func newClient() (*http.Client, error) {
client := &http.Client{}
if config().proxyEnabled() {
proxyStr := config().proxyURL()
proxyURL, err := url.Parse(proxyStr)
if err != nil {
return nil, errors.Wrap(err, "Parse proxy url ERROR:")
}
transport := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
}
//adding the Transport object to the http Client
client.Transport = transport
}
return client, nil
}