@@ -25,8 +25,26 @@ func buildURL(baseStr string, endpoint string) *url.URL {
2525}
2626
2727// Request sends a HTTP request to the server.
28- func Request (base , endpoint , method , username , password string , hasBody bool , data interface {}) (interface {}, error ) {
29- client := & http.Client {}
28+ func Request (base , endpoint , method , proxy , username , password string , hasBody bool , data interface {}) (interface {}, error ) {
29+ transport := http .DefaultTransport
30+
31+ if len (proxy ) > 0 {
32+ log .Printf ("Using proxy '%s'" , proxy )
33+
34+ proxyURL , err := url .Parse (proxy )
35+ if err != nil {
36+ return nil , err
37+ }
38+
39+ transport = & http.Transport {
40+ Proxy : http .ProxyURL (proxyURL ),
41+ }
42+ }
43+
44+ client := & http.Client {
45+ Transport : transport ,
46+ }
47+
3048 url := buildURL (base , endpoint )
3149
3250 var reqBodyReader io.Reader
@@ -77,21 +95,21 @@ func Request(base, endpoint, method, username, password string, hasBody bool, da
7795}
7896
7997// Delete sends a HTTP DELETE request to the server.
80- func Delete (base , endpoint , username , password string ) (interface {}, error ) {
81- return Request (base , endpoint , "DELETE" , username , password , false , nil )
98+ func Delete (base , endpoint , proxy , username , password string ) (interface {}, error ) {
99+ return Request (base , endpoint , "DELETE" , proxy , username , password , false , nil )
82100}
83101
84102// Get sends a HTTP GET request to the server.
85- func Get (base , endpoint , username , password string ) (interface {}, error ) {
86- return Request (base , endpoint , "GET" , username , password , false , nil )
103+ func Get (base , endpoint , proxy , username , password string ) (interface {}, error ) {
104+ return Request (base , endpoint , "GET" , proxy , username , password , false , nil )
87105}
88106
89107// Post sends a HTTP POST request to the server.
90- func Post (base , endpoint , username , password string , data interface {}) (interface {}, error ) {
91- return Request (base , endpoint , "POST" , username , password , true , data )
108+ func Post (base , endpoint , proxy , username , password string , data interface {}) (interface {}, error ) {
109+ return Request (base , endpoint , "POST" , proxy , username , password , true , data )
92110}
93111
94112// Put sends a HTTP PUT request to the server.
95- func Put (base , endpoint , username , password string , data interface {}) (interface {}, error ) {
96- return Request (base , endpoint , "PUT" , username , password , true , data )
113+ func Put (base , endpoint , proxy , username , password string , data interface {}) (interface {}, error ) {
114+ return Request (base , endpoint , "PUT" , proxy , username , password , true , data )
97115}
0 commit comments