feat(client): implement exponential backoff retry for network errors

This commit is contained in:
2026-09-21 21:44:12 +03:30
parent 099ec2150e
commit c6e2ce7fd5
6 changed files with 335 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"strconv"
"strings"
"time"
)
@@ -15,6 +16,7 @@ type config struct {
ZarinHubUsername string
ZarinHubPassword string
ZarinHubTimeout time.Duration
ZarinHubRetries int
DatabasePath string
}
@@ -44,6 +46,18 @@ func readConfig(getenv func(string) string) (config, error) {
)
}
retriesText := valueOrDefault(
getenv("ZARINHUB_RETRIES"),
"2",
)
retries, err := strconv.Atoi(retriesText)
if err != nil || retries < 0 {
return config{}, fmt.Errorf(
"ZARINHUB_RETRIES must be a non-negative integer",
)
}
return config{
ServerAddr: valueOrDefault(
getenv("SERVER_ADDR"),
@@ -64,6 +78,7 @@ func readConfig(getenv func(string) string) (config, error) {
ZarinHubUsername: username,
ZarinHubPassword: password,
ZarinHubTimeout: timeout,
ZarinHubRetries: retries,
DatabasePath: valueOrDefault(
getenv("DATABASE_PATH"),
"./card-to-iban.db",