mirror of
https://git.swurl.xyz/swirl/link.git
synced 2023-11-08 10:44:52 +02:00
Fix(main.go): Add error case checking to retry.
This commit is contained in:
parent
15d3d2837f
commit
5ee34dfc2f
1 changed files with 13 additions and 1 deletions
14
main.go
14
main.go
|
@ -44,6 +44,13 @@ type Retry struct {
|
|||
retryAttemptCount int
|
||||
}
|
||||
|
||||
func NewRetry(retryAttemptCount int) (Retry, error) {
|
||||
if retryAttemptCount < 1 {
|
||||
return Retry{}, errors.New("retry attempt count must be greater than zero")
|
||||
}
|
||||
return Retry{retryAttemptCount}, nil
|
||||
}
|
||||
|
||||
func (r Retry) Do(f func() error) (err error) {
|
||||
for i := 0; i < r.retryAttemptCount; i++ {
|
||||
err = f()
|
||||
|
@ -275,7 +282,12 @@ func main() {
|
|||
if *v {
|
||||
applicationLogger = log.New(os.Stdout, logPrefix, 0)
|
||||
}
|
||||
db, err := NewDB(applicationLogger, *dbFilePath, *hashSeed, Retry{3})
|
||||
retry, err := NewRetry(3)
|
||||
if err != nil {
|
||||
startupLogger.Fatal(err)
|
||||
return
|
||||
}
|
||||
db, err := NewDB(applicationLogger, *dbFilePath, *hashSeed, retry)
|
||||
if err != nil {
|
||||
startupLogger.Fatal(err)
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue