-
Notifications
You must be signed in to change notification settings - Fork 0
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
Andrey Anisimov
committed
Aug 11, 2021
1 parent
79046ac
commit 114eb4e
Showing
6 changed files
with
13 additions
and
143 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
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 |
---|---|---|
@@ -1,70 +1,10 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/avast/retry-go" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/t4rest/t4rest-go/httpclient" | ||
"github.com/t4rest/t4rest-go/logger" | ||
"github.com/t4rest/t4rest-go/module" | ||
ret "github.com/t4rest/t4rest-go/retry" | ||
"github.com/t4rest/t4rest-go/trace" | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
|
||
log := logger.New(logger.Conf{AppID: "AppID", LogLevel: "debug"}) | ||
defer log.Flush() | ||
|
||
flush, err := trace.New(trace.Conf{AppID: "AppID", CollectorEndpoint: "http://localhost:14268/api/traces"}) | ||
if err != nil { | ||
log.Fatal(errors.Wrap(err, "trace.New")) | ||
} | ||
defer flush() | ||
|
||
ctx := context.Background() | ||
|
||
httpClient := httpclient.New(httpclient.Conf{HTTPTimeout: 10 * time.Second}) | ||
|
||
// retry example | ||
err500 := errors.New("Server error") | ||
|
||
r := ret.New(ret.Conf{Attempts: 3, DelayMs: 10 * time.Second, MaxDelayMs: 30 * time.Second}) | ||
err = r.Do( | ||
func() error { | ||
|
||
req, err := http.NewRequest(http.MethodGet, "https://google.com", nil) | ||
if err != nil { | ||
return err | ||
} | ||
req.Header.Set("Content-Type", "application/json") | ||
resp, err := httpClient.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() //nolint: errcheck | ||
|
||
if resp.StatusCode >= http.StatusInternalServerError { | ||
return errors.Wrap(err500, "server is down") | ||
} | ||
|
||
return nil | ||
}, | ||
retry.OnRetry(func(i uint, err error) { | ||
log.With("retry_attempt", i, "error", err).Info("onRetry") | ||
}), | ||
retry.RetryIf(func(err error) bool { | ||
return errors.Is(err, err500) | ||
}), | ||
retry.Context(ctx), | ||
) | ||
if err != nil { | ||
log.With("error", err).Error("Get(google.com)") | ||
} | ||
|
||
module.Run(log) | ||
fmt.Println("golang") | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.