Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sohamkamani committed Mar 27, 2019
1 parent f5ba761 commit 3af683e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions httpclient/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func ExampleWithHTTPTimeout_expired() {
return
}
fmt.Println("Response status : ", res.StatusCode)
// Output: error: Get https://www.gojek.io/: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
}

func ExampleWithRetryCount() {
Expand All @@ -86,6 +87,7 @@ func ExampleWithRetryCount() {
return
}
fmt.Println("Response status : ", res.StatusCode)
// Output: error: Get https://www.gojek.io/: net/http: request canceled (Client.Timeout exceeded while awaiting headers), Get https://www.gojek.io/: net/http: request canceled (Client.Timeout exceeded while awaiting headers), Get https://www.gojek.io/: net/http: request canceled (Client.Timeout exceeded while awaiting headers), Get https://www.gojek.io/: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
}

type mockClient struct{}
Expand Down Expand Up @@ -114,20 +116,20 @@ func (m *mockRetrier) NextInterval(attempt int) time.Duration {
}

func ExampleWithRetrier() {
c := NewClient(WithHTTPTimeout(1*time.Millisecond), WithRetryCount(3), WithRetrier(&mockRetrier{}))
c := NewClient(WithHTTPTimeout(10*time.Millisecond), WithRetryCount(3), WithRetrier(&mockRetrier{}))
req, err := http.NewRequest(http.MethodGet, "https://www.gojek.io/", nil)
if err != nil {
panic(err)
}
res, err := c.Do(req)
if err != nil {
fmt.Println("error")
fmt.Println("error:", err)
return
}
fmt.Println("Response status : ", res.StatusCode)
// Output: retry attempt 0
// retry attempt 1
// retry attempt 2
// retry attempt 3
// error
// error: Get https://www.gojek.io/: net/http: request canceled (Client.Timeout exceeded while awaiting headers), Get https://www.gojek.io/: net/http: request canceled (Client.Timeout exceeded while awaiting headers), Get https://www.gojek.io/: net/http: request canceled (Client.Timeout exceeded while awaiting headers), Get https://www.gojek.io/: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
}

0 comments on commit 3af683e

Please sign in to comment.