@@ -76,6 +76,8 @@ type Client struct {
76
76
servers []* url.URL
77
77
}
78
78
79
+ // NewClient creates a new Client with the given configuration.
80
+ // It returns an error if no proxies are provided in the configuration.
79
81
func NewClient (config Config ) (* Client , error ) {
80
82
if len (config .Proxies ) == 0 {
81
83
return nil , errors .New ("at least one proxy is required" )
@@ -240,6 +242,8 @@ func (c *Client) do(req *http.Request) (*http.Response, error) {
240
242
return nil , fmt .Errorf ("all proxy servers failed, last error: %v" , lastErr )
241
243
}
242
244
245
+ // Do sends an HTTP request and returns an HTTP response, following policy
246
+ // (such as redirects, cookies, auth) as configured on the client.
243
247
func (c * Client ) Do (req * http.Request ) (* http.Response , error ) {
244
248
v , err , _ := c .sf .Do (req .URL .Host , func () (interface {}, error ) {
245
249
var resp * http.Response
@@ -267,6 +271,8 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
267
271
return v .(* http.Response ), nil
268
272
}
269
273
274
+ // NewRequest creates a new http.Request with the provided method, URL, and optional body.
275
+ // It sets the default User-Agent if configured.
270
276
func (c * Client ) NewRequest (method , url string , body io.Reader ) (* http.Request , error ) {
271
277
req , err := http .NewRequest (method , url , body )
272
278
if err != nil {
@@ -281,6 +287,7 @@ func (c *Client) NewRequest(method, url string, body io.Reader) (*http.Request,
281
287
return req , nil
282
288
}
283
289
290
+ // Get issues a GET request to the specified URL.
284
291
func (c * Client ) Get (url string ) (* http.Response , error ) {
285
292
req , err := c .NewRequest ("GET" , url , nil )
286
293
if err != nil {
@@ -289,6 +296,7 @@ func (c *Client) Get(url string) (*http.Response, error) {
289
296
return c .Do (req )
290
297
}
291
298
299
+ // Post issues a POST request to the specified URL with the given content type and body.
292
300
func (c * Client ) Post (url , contentType string , body io.Reader ) (* http.Response , error ) {
293
301
req , err := c .NewRequest ("POST" , url , body )
294
302
if err != nil {
@@ -298,6 +306,7 @@ func (c *Client) Post(url, contentType string, body io.Reader) (*http.Response,
298
306
return c .Do (req )
299
307
}
300
308
309
+ // Head issues a HEAD request to the specified URL.
301
310
func (c * Client ) Head (url string ) (* http.Response , error ) {
302
311
req , err := c .NewRequest ("HEAD" , url , nil )
303
312
if err != nil {
0 commit comments