mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 04:15:54 +02:00
33 lines
741 B
Go
33 lines
741 B
Go
package apiclient
|
|
|
|
type StatusCodeConfig struct {
|
|
MaxAttempts int
|
|
Backoff bool
|
|
InvalidateToken bool
|
|
}
|
|
|
|
type RetryConfig struct {
|
|
StatusCodeConfig map[int]StatusCodeConfig
|
|
}
|
|
|
|
type RetryConfigOption func(*RetryConfig)
|
|
|
|
func NewRetryConfig(options ...RetryConfigOption) *RetryConfig {
|
|
rc := &RetryConfig{
|
|
StatusCodeConfig: make(map[int]StatusCodeConfig),
|
|
}
|
|
for _, opt := range options {
|
|
opt(rc)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
func WithStatusCodeConfig(statusCode int, maxAttempts int, backOff bool, invalidateToken bool) RetryConfigOption {
|
|
return func(rc *RetryConfig) {
|
|
rc.StatusCodeConfig[statusCode] = StatusCodeConfig{
|
|
MaxAttempts: maxAttempts,
|
|
Backoff: backOff,
|
|
InvalidateToken: invalidateToken,
|
|
}
|
|
}
|
|
}
|