@@ -8,13 +8,22 @@ import (
88 "os"
99 "path/filepath"
1010 "strings"
11+ "time"
12+ )
13+
14+ const (
15+ defaultHTTPTimeoutSeconds = 10
16+ defaultHTTPReadRetryBackoffMillis = 250
1117)
1218
1319type AppConfig struct {
14- APIBaseURL string `json:"apiBaseUrl"`
15- AccessKey string `json:"accessKey"`
16- SecretKey string `json:"secretKey"`
17- Language string `json:"language,omitempty"`
20+ APIBaseURL string `json:"apiBaseUrl"`
21+ AccessKey string `json:"accessKey"`
22+ SecretKey string `json:"secretKey"`
23+ Language string `json:"language,omitempty"`
24+ HTTPTimeoutSeconds int `json:"httpTimeoutSeconds,omitempty"`
25+ HTTPReadMaxRetries int `json:"httpReadMaxRetries,omitempty"`
26+ HTTPReadRetryBackoffMillis int `json:"httpReadRetryBackoffMillis,omitempty"`
1827}
1928
2029func (c AppConfig ) Validate () error {
@@ -31,6 +40,15 @@ func (c AppConfig) Validate() error {
3140 if normalized := i18n .NormalizeLanguage (c .Language ); normalized == "" && strings .TrimSpace (c .Language ) != "" {
3241 return errors .New (i18n .T ("config.languageUnsupported" ))
3342 }
43+ if c .HTTPTimeoutSeconds < 0 {
44+ return errors .New (i18n .TFor (language , "config.httpTimeoutSecondsInvalid" ))
45+ }
46+ if c .HTTPReadMaxRetries < 0 {
47+ return errors .New (i18n .TFor (language , "config.httpReadMaxRetriesInvalid" ))
48+ }
49+ if c .HTTPReadRetryBackoffMillis < 0 {
50+ return errors .New (i18n .TFor (language , "config.httpReadRetryBackoffMillisInvalid" ))
51+ }
3452
3553 parsed , err := url .Parse (strings .TrimSpace (c .APIBaseURL ))
3654 if err != nil {
@@ -63,6 +81,35 @@ func (c AppConfig) WithDefaults() AppConfig {
6381 return c
6482}
6583
84+ func (c AppConfig ) HTTPTimeout () time.Duration {
85+ return time .Duration (c .HTTPTimeoutSecondsValue ()) * time .Second
86+ }
87+
88+ func (c AppConfig ) HTTPTimeoutSecondsValue () int {
89+ if c .HTTPTimeoutSeconds <= 0 {
90+ return defaultHTTPTimeoutSeconds
91+ }
92+ return c .HTTPTimeoutSeconds
93+ }
94+
95+ func (c AppConfig ) HTTPReadMaxRetriesValue () int {
96+ if c .HTTPReadMaxRetries <= 0 {
97+ return 0
98+ }
99+ return c .HTTPReadMaxRetries
100+ }
101+
102+ func (c AppConfig ) HTTPReadRetryBackoff () time.Duration {
103+ return time .Duration (c .HTTPReadRetryBackoffMillisValue ()) * time .Millisecond
104+ }
105+
106+ func (c AppConfig ) HTTPReadRetryBackoffMillisValue () int {
107+ if c .HTTPReadRetryBackoffMillis <= 0 {
108+ return defaultHTTPReadRetryBackoffMillis
109+ }
110+ return c .HTTPReadRetryBackoffMillis
111+ }
112+
66113type Service struct {
67114 path string
68115}
0 commit comments