-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8bb498f
commit 10bc257
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package examplefullstack | ||
|
||
import ( | ||
"context" | ||
aulogging "github.com/StephanHCB/go-autumn-logging" | ||
aurestclientapi "github.com/StephanHCB/go-autumn-restclient/api" | ||
auresthttpclient "github.com/StephanHCB/go-autumn-restclient/implementation/httpclient" | ||
aurestlogging "github.com/StephanHCB/go-autumn-restclient/implementation/requestlogging" | ||
aurestretry "github.com/StephanHCB/go-autumn-restclient/implementation/retry" | ||
"net/http" | ||
) | ||
|
||
func example() { | ||
// assumes you set up logging by importing one of the go-autumn-logging-xxx dependencies | ||
// | ||
// for this example, let's set up a logger that does nothing, so we don't pull in these dependencies here | ||
// | ||
// This of course makes the requestLoggingClient not work. | ||
aulogging.SetupNoLoggerForTesting() | ||
|
||
// set up | ||
httpClient, _ := auresthttpclient.New(0, []byte{}, nil) | ||
requestLoggingClient := aurestlogging.New(httpClient) | ||
retryingClient := aurestretry.New(requestLoggingClient, 2, func(ctx context.Context, response *aurestclientapi.ParsedResponse, err error) bool { | ||
return response.Status >= 500 || err != nil | ||
}, nil) | ||
|
||
// now make a request | ||
bodyDto := make(map[string]interface{}) | ||
|
||
response := aurestclientapi.ParsedResponse{ | ||
Body: &bodyDto, | ||
} | ||
_ = retryingClient.Perform(context.Background(), http.MethodGet, "https://some.rest.api", nil, &response) | ||
|
||
// now bodyDto is filled with the response | ||
} |