@@ -8,22 +8,22 @@ import (
88 "github.com/acoshift/pgsql"
99)
1010
11- // BackoffConfig contains common configuration for all backoff strategies
12- type BackoffConfig struct {
11+ // Config contains common configuration for all backoff strategies
12+ type Config struct {
1313 BaseDelay time.Duration // Base delay for backoff
1414 MaxDelay time.Duration // Maximum delay cap
1515}
1616
17- // ExponentialBackoffConfig contains configuration for exponential backoff
18- type ExponentialBackoffConfig struct {
19- BackoffConfig
17+ // ExponentialConfig contains configuration for exponential backoff
18+ type ExponentialConfig struct {
19+ Config
2020 Multiplier float64 // Multiplier for exponential growth
2121 JitterType JitterType
2222}
2323
24- // LinearBackoffConfig contains configuration for linear backoff
25- type LinearBackoffConfig struct {
26- BackoffConfig
24+ // LinearConfig contains configuration for linear backoff
25+ type LinearConfig struct {
26+ Config
2727 Increment time.Duration // Amount to increase delay each attempt
2828}
2929
@@ -39,8 +39,8 @@ const (
3939 EqualJitter
4040)
4141
42- // NewExponentialBackoff creates a new exponential backoff function
43- func NewExponentialBackoff (config ExponentialBackoffConfig ) pgsql.BackoffDelayFunc {
42+ // NewExponential creates a new exponential backoff function
43+ func NewExponential (config ExponentialConfig ) pgsql.BackoffDelayFunc {
4444 return func (attempt int ) time.Duration {
4545 baseDelay := time .Duration (float64 (config .BaseDelay ) * math .Pow (config .Multiplier , float64 (attempt )))
4646 if baseDelay > config .MaxDelay {
@@ -72,8 +72,8 @@ func NewExponentialBackoff(config ExponentialBackoffConfig) pgsql.BackoffDelayFu
7272 }
7373}
7474
75- // NewLinearBackoff creates a new linear backoff function
76- func NewLinearBackoff (config LinearBackoffConfig ) pgsql.BackoffDelayFunc {
75+ // NewLinear creates a new linear backoff function
76+ func NewLinear (config LinearConfig ) pgsql.BackoffDelayFunc {
7777 return func (attempt int ) time.Duration {
7878 delay := config .BaseDelay + time .Duration (attempt )* config .Increment
7979 if delay > config .MaxDelay {
@@ -83,9 +83,9 @@ func NewLinearBackoff(config LinearBackoffConfig) pgsql.BackoffDelayFunc {
8383 }
8484}
8585
86- func DefaultExponentialBackoff () pgsql.BackoffDelayFunc {
87- return NewExponentialBackoff ( ExponentialBackoffConfig {
88- BackoffConfig : BackoffConfig {
86+ func DefaultExponential () pgsql.BackoffDelayFunc {
87+ return NewExponential ( ExponentialConfig {
88+ Config : Config {
8989 BaseDelay : 100 * time .Millisecond ,
9090 MaxDelay : 5 * time .Second ,
9191 },
@@ -94,9 +94,9 @@ func DefaultExponentialBackoff() pgsql.BackoffDelayFunc {
9494 })
9595}
9696
97- func DefaultExponentialBackoffWithFullJitter () pgsql.BackoffDelayFunc {
98- return NewExponentialBackoff ( ExponentialBackoffConfig {
99- BackoffConfig : BackoffConfig {
97+ func DefaultExponentialWithFullJitter () pgsql.BackoffDelayFunc {
98+ return NewExponential ( ExponentialConfig {
99+ Config : Config {
100100 BaseDelay : 100 * time .Millisecond ,
101101 MaxDelay : 5 * time .Second ,
102102 },
@@ -105,9 +105,9 @@ func DefaultExponentialBackoffWithFullJitter() pgsql.BackoffDelayFunc {
105105 })
106106}
107107
108- func DefaultExponentialBackoffWithEqualJitter () pgsql.BackoffDelayFunc {
109- return NewExponentialBackoff ( ExponentialBackoffConfig {
110- BackoffConfig : BackoffConfig {
108+ func DefaultExponentialWithEqualJitter () pgsql.BackoffDelayFunc {
109+ return NewExponential ( ExponentialConfig {
110+ Config : Config {
111111 BaseDelay : 100 * time .Millisecond ,
112112 MaxDelay : 5 * time .Second ,
113113 },
@@ -116,9 +116,9 @@ func DefaultExponentialBackoffWithEqualJitter() pgsql.BackoffDelayFunc {
116116 })
117117}
118118
119- func DefaultLinearBackoff () pgsql.BackoffDelayFunc {
120- return NewLinearBackoff ( LinearBackoffConfig {
121- BackoffConfig : BackoffConfig {
119+ func DefaultLinear () pgsql.BackoffDelayFunc {
120+ return NewLinear ( LinearConfig {
121+ Config : Config {
122122 BaseDelay : 100 * time .Millisecond ,
123123 MaxDelay : 5 * time .Second ,
124124 },
0 commit comments