Skip to content

Commit 9a1148e

Browse files
committed
reduce verbose
1 parent ffcd402 commit 9a1148e

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

backoff/backoff.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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
},

backoff/backoff_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import (
77
"github.com/acoshift/pgsql/backoff"
88
)
99

10-
func TestExponentialBackoff(t *testing.T) {
10+
func TestExponential(t *testing.T) {
1111
t.Parallel()
1212

13-
config := backoff.ExponentialBackoffConfig{
14-
BackoffConfig: backoff.BackoffConfig{
13+
config := backoff.ExponentialConfig{
14+
Config: backoff.Config{
1515
BaseDelay: 10 * time.Millisecond,
1616
MaxDelay: 1 * time.Second,
1717
},
1818
Multiplier: 2.0,
1919
}
20-
backoff := backoff.NewExponentialBackoff(config)
20+
backoff := backoff.NewExponential(config)
2121

2222
// Test exponential growth
2323
delays := []time.Duration{}
@@ -42,18 +42,18 @@ func TestExponentialBackoff(t *testing.T) {
4242
}
4343
}
4444

45-
func TestExponentialBackoffWithFullJitter(t *testing.T) {
45+
func TestExponentialWithFullJitter(t *testing.T) {
4646
t.Parallel()
4747

48-
config := backoff.ExponentialBackoffConfig{
49-
BackoffConfig: backoff.BackoffConfig{
48+
config := backoff.ExponentialConfig{
49+
Config: backoff.Config{
5050
BaseDelay: 100 * time.Millisecond,
5151
MaxDelay: 1 * time.Second,
5252
},
5353
Multiplier: 2.0,
5454
JitterType: backoff.FullJitter,
5555
}
56-
backoff := backoff.NewExponentialBackoff(config)
56+
backoff := backoff.NewExponential(config)
5757

5858
// Test that jitter introduces randomness
5959
var delays []time.Duration
@@ -83,18 +83,18 @@ func TestExponentialBackoffWithFullJitter(t *testing.T) {
8383
}
8484
}
8585

86-
func TestExponentialBackoffWithEqualJitter(t *testing.T) {
86+
func TestExponentialWithEqualJitter(t *testing.T) {
8787
t.Parallel()
8888

89-
config := backoff.ExponentialBackoffConfig{
90-
BackoffConfig: backoff.BackoffConfig{
89+
config := backoff.ExponentialConfig{
90+
Config: backoff.Config{
9191
BaseDelay: 100 * time.Millisecond,
9292
MaxDelay: 1 * time.Second,
9393
},
9494
Multiplier: 2.0,
9595
JitterType: backoff.EqualJitter,
9696
}
97-
backoff := backoff.NewExponentialBackoff(config)
97+
backoff := backoff.NewExponential(config)
9898

9999
delay := backoff(2)
100100

@@ -116,14 +116,14 @@ func TestExponentialBackoffWithEqualJitter(t *testing.T) {
116116
func TestLinearBackoff(t *testing.T) {
117117
t.Parallel()
118118

119-
config := backoff.LinearBackoffConfig{
120-
BackoffConfig: backoff.BackoffConfig{
119+
config := backoff.LinearConfig{
120+
Config: backoff.Config{
121121
BaseDelay: 100 * time.Millisecond,
122122
MaxDelay: 1 * time.Second,
123123
},
124124
Increment: 100 * time.Millisecond,
125125
}
126-
backoff := backoff.NewLinearBackoff(config)
126+
backoff := backoff.NewLinear(config)
127127

128128
// Test linear growth
129129
delays := []time.Duration{}

0 commit comments

Comments
 (0)