File tree 2 files changed +26
-3
lines changed
2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 2
2
package helpers
3
3
4
4
import (
5
+ "encoding/json"
5
6
"fmt"
6
7
"os"
7
8
"path/filepath"
@@ -33,3 +34,25 @@ func SafeOpenFile(filePath string) (*os.File, error) {
33
34
// Open the file if the path is deemed safe
34
35
return os .Open (absPath )
35
36
}
37
+
38
+ // UnmarshalJSON parses the duration from JSON string.
39
+ func (d * JSONDuration ) UnmarshalJSON (b []byte ) error {
40
+ var s string
41
+ if err := json .Unmarshal (b , & s ); err != nil {
42
+ return err
43
+ }
44
+ duration , err := time .ParseDuration (s )
45
+ if err != nil {
46
+ return err
47
+ }
48
+ * d = JSONDuration (duration )
49
+ return nil
50
+ }
51
+
52
+ // Duration returns the time.Duration value.
53
+ func (d JSONDuration ) Duration () time.Duration {
54
+ return time .Duration (d )
55
+ }
56
+
57
+ // JSONDuration wraps time.Duration for custom JSON unmarshalling.
58
+ type JSONDuration time.Duration
Original file line number Diff line number Diff line change @@ -95,9 +95,9 @@ type ConcurrencyConfig struct {
95
95
96
96
// TimeoutConfig holds custom timeout settings.
97
97
type TimeoutConfig struct {
98
- CustomTimeout time.Duration // Custom timeout for the HTTP client
99
- TokenRefreshBufferPeriod time.Duration // Buffer period before token expiry to attempt token refresh
100
- TotalRetryDuration time.Duration // Total duration to attempt retries
98
+ CustomTimeout time.Duration `json:"CustomTimeout,omitempty"` // Custom timeout for the HTTP client
99
+ TokenRefreshBufferPeriod time.Duration `json:"TokenRefreshBufferPeriod,omitempty"` // Buffer period before token expiry to attempt token refresh
100
+ TotalRetryDuration time.Duration `json:"TotalRetryDuration,omitempty"` // Total duration to attempt retries
101
101
}
102
102
103
103
// RedirectConfig holds configuration related to redirect handling.
You can’t perform that action at this time.
0 commit comments