Skip to content

Commit 725f619

Browse files
committed
chore: modernize
1 parent 3471fab commit 725f619

File tree

14 files changed

+64
-64
lines changed

14 files changed

+64
-64
lines changed

buffer/threshold.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func parseExpression(in string) (hpredicate, error) {
2828
LE: le,
2929
GE: ge,
3030
},
31-
Functions: map[string]interface{}{
31+
Functions: map[string]any{
3232
"RequestMethod": requestMethod,
3333
"IsNetworkError": isNetworkError,
3434
"Attempts": attempts,
@@ -93,7 +93,7 @@ func not(p hpredicate) hpredicate {
9393
}
9494

9595
// eq returns predicate that tests for equality of the value of the mapper and the constant.
96-
func eq(m interface{}, value interface{}) (hpredicate, error) {
96+
func eq(m any, value any) (hpredicate, error) {
9797
switch mapper := m.(type) {
9898
case toString:
9999
return stringEQ(mapper, value)
@@ -105,7 +105,7 @@ func eq(m interface{}, value interface{}) (hpredicate, error) {
105105
}
106106

107107
// neq returns predicate that tests for inequality of the value of the mapper and the constant.
108-
func neq(m interface{}, value interface{}) (hpredicate, error) {
108+
func neq(m any, value any) (hpredicate, error) {
109109
p, err := eq(m, value)
110110
if err != nil {
111111
return nil, err
@@ -115,7 +115,7 @@ func neq(m interface{}, value interface{}) (hpredicate, error) {
115115
}
116116

117117
// lt returns predicate that tests that value of the mapper function is less than the constant.
118-
func lt(m interface{}, value interface{}) (hpredicate, error) {
118+
func lt(m any, value any) (hpredicate, error) {
119119
switch mapper := m.(type) {
120120
case toInt:
121121
return intLT(mapper, value)
@@ -125,7 +125,7 @@ func lt(m interface{}, value interface{}) (hpredicate, error) {
125125
}
126126

127127
// le returns predicate that tests that value of the mapper function is less or equal than the constant.
128-
func le(m interface{}, value interface{}) (hpredicate, error) {
128+
func le(m any, value any) (hpredicate, error) {
129129
l, err := lt(m, value)
130130
if err != nil {
131131
return nil, err
@@ -142,7 +142,7 @@ func le(m interface{}, value interface{}) (hpredicate, error) {
142142
}
143143

144144
// gt returns predicate that tests that value of the mapper function is greater than the constant.
145-
func gt(m interface{}, value interface{}) (hpredicate, error) {
145+
func gt(m any, value any) (hpredicate, error) {
146146
switch mapper := m.(type) {
147147
case toInt:
148148
return intGT(mapper, value)
@@ -152,7 +152,7 @@ func gt(m interface{}, value interface{}) (hpredicate, error) {
152152
}
153153

154154
// ge returns predicate that tests that value of the mapper function is less or equal than the constant.
155-
func ge(m interface{}, value interface{}) (hpredicate, error) {
155+
func ge(m any, value any) (hpredicate, error) {
156156
g, err := gt(m, value)
157157
if err != nil {
158158
return nil, err
@@ -168,7 +168,7 @@ func ge(m interface{}, value interface{}) (hpredicate, error) {
168168
}, nil
169169
}
170170

171-
func stringEQ(m toString, val interface{}) (hpredicate, error) {
171+
func stringEQ(m toString, val any) (hpredicate, error) {
172172
value, ok := val.(string)
173173
if !ok {
174174
return nil, fmt.Errorf("expected string, got %T", val)
@@ -179,7 +179,7 @@ func stringEQ(m toString, val interface{}) (hpredicate, error) {
179179
}, nil
180180
}
181181

182-
func intEQ(m toInt, val interface{}) (hpredicate, error) {
182+
func intEQ(m toInt, val any) (hpredicate, error) {
183183
value, ok := val.(int)
184184
if !ok {
185185
return nil, fmt.Errorf("expected int, got %T", val)
@@ -190,7 +190,7 @@ func intEQ(m toInt, val interface{}) (hpredicate, error) {
190190
}, nil
191191
}
192192

193-
func intLT(m toInt, val interface{}) (hpredicate, error) {
193+
func intLT(m toInt, val any) (hpredicate, error) {
194194
value, ok := val.(int)
195195
if !ok {
196196
return nil, fmt.Errorf("expected int, got %T", val)
@@ -201,7 +201,7 @@ func intLT(m toInt, val interface{}) (hpredicate, error) {
201201
}, nil
202202
}
203203

204-
func intGT(m toInt, val interface{}) (hpredicate, error) {
204+
func intGT(m toInt, val any) (hpredicate, error) {
205205
value, ok := val.(int)
206206
if !ok {
207207
return nil, fmt.Errorf("expected int, got %T", val)

cbreaker/predicates.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func parseExpression(in string) (hpredicate, error) {
2222
GT: gt,
2323
GE: ge,
2424
},
25-
Functions: map[string]interface{}{
25+
Functions: map[string]any{
2626
"LatencyAtQuantileMS": latencyAtQuantile,
2727
"NetworkErrorRatio": networkErrorRatio,
2828
"ResponseCodeRatio": responseCodeRatio,
@@ -107,7 +107,7 @@ func not(p hpredicate) hpredicate {
107107
}
108108

109109
// eq returns predicate that tests for equality of the value of the mapper and the constant.
110-
func eq(m interface{}, value interface{}) (hpredicate, error) {
110+
func eq(m any, value any) (hpredicate, error) {
111111
switch mapper := m.(type) {
112112
case toInt:
113113
return intEQ(mapper, value)
@@ -119,7 +119,7 @@ func eq(m interface{}, value interface{}) (hpredicate, error) {
119119
}
120120

121121
// neq returns predicate that tests for inequality of the value of the mapper and the constant.
122-
func neq(m interface{}, value interface{}) (hpredicate, error) {
122+
func neq(m any, value any) (hpredicate, error) {
123123
p, err := eq(m, value)
124124
if err != nil {
125125
return nil, err
@@ -129,7 +129,7 @@ func neq(m interface{}, value interface{}) (hpredicate, error) {
129129
}
130130

131131
// lt returns predicate that tests that value of the mapper function is less than the constant.
132-
func lt(m interface{}, value interface{}) (hpredicate, error) {
132+
func lt(m any, value any) (hpredicate, error) {
133133
switch mapper := m.(type) {
134134
case toInt:
135135
return intLT(mapper, value)
@@ -141,7 +141,7 @@ func lt(m interface{}, value interface{}) (hpredicate, error) {
141141
}
142142

143143
// le returns predicate that tests that value of the mapper function is less or equal than the constant.
144-
func le(m interface{}, value interface{}) (hpredicate, error) {
144+
func le(m any, value any) (hpredicate, error) {
145145
l, err := lt(m, value)
146146
if err != nil {
147147
return nil, err
@@ -158,7 +158,7 @@ func le(m interface{}, value interface{}) (hpredicate, error) {
158158
}
159159

160160
// gt returns predicate that tests that value of the mapper function is greater than the constant.
161-
func gt(m interface{}, value interface{}) (hpredicate, error) {
161+
func gt(m any, value any) (hpredicate, error) {
162162
switch mapper := m.(type) {
163163
case toInt:
164164
return intGT(mapper, value)
@@ -170,7 +170,7 @@ func gt(m interface{}, value interface{}) (hpredicate, error) {
170170
}
171171

172172
// ge returns predicate that tests that value of the mapper function is less or equal than the constant.
173-
func ge(m interface{}, value interface{}) (hpredicate, error) {
173+
func ge(m any, value any) (hpredicate, error) {
174174
g, err := gt(m, value)
175175
if err != nil {
176176
return nil, err
@@ -186,7 +186,7 @@ func ge(m interface{}, value interface{}) (hpredicate, error) {
186186
}, nil
187187
}
188188

189-
func intEQ(m toInt, val interface{}) (hpredicate, error) {
189+
func intEQ(m toInt, val any) (hpredicate, error) {
190190
value, ok := val.(int)
191191
if !ok {
192192
return nil, fmt.Errorf("expected int, got %T", val)
@@ -197,7 +197,7 @@ func intEQ(m toInt, val interface{}) (hpredicate, error) {
197197
}, nil
198198
}
199199

200-
func float64EQ(m toFloat64, val interface{}) (hpredicate, error) {
200+
func float64EQ(m toFloat64, val any) (hpredicate, error) {
201201
value, ok := val.(float64)
202202
if !ok {
203203
return nil, fmt.Errorf("expected float64, got %T", val)
@@ -208,7 +208,7 @@ func float64EQ(m toFloat64, val interface{}) (hpredicate, error) {
208208
}, nil
209209
}
210210

211-
func intLT(m toInt, val interface{}) (hpredicate, error) {
211+
func intLT(m toInt, val any) (hpredicate, error) {
212212
value, ok := val.(int)
213213
if !ok {
214214
return nil, fmt.Errorf("expected int, got %T", val)
@@ -219,7 +219,7 @@ func intLT(m toInt, val interface{}) (hpredicate, error) {
219219
}, nil
220220
}
221221

222-
func intGT(m toInt, val interface{}) (hpredicate, error) {
222+
func intGT(m toInt, val any) (hpredicate, error) {
223223
value, ok := val.(int)
224224
if !ok {
225225
return nil, fmt.Errorf("expected int, got %T", val)
@@ -230,7 +230,7 @@ func intGT(m toInt, val interface{}) (hpredicate, error) {
230230
}, nil
231231
}
232232

233-
func float64LT(m toFloat64, val interface{}) (hpredicate, error) {
233+
func float64LT(m toFloat64, val any) (hpredicate, error) {
234234
value, ok := val.(float64)
235235
if !ok {
236236
return nil, fmt.Errorf("expected int, got %T", val)
@@ -241,7 +241,7 @@ func float64LT(m toFloat64, val interface{}) (hpredicate, error) {
241241
}, nil
242242
}
243243

244-
func float64GT(m toFloat64, val interface{}) (hpredicate, error) {
244+
func float64GT(m toFloat64, val any) (hpredicate, error) {
245245
value, ok := val.(float64)
246246
if !ok {
247247
return nil, fmt.Errorf("expected int, got %T", val)

internal/holsterv4/clock/duration.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type DurationJSON struct {
99
Duration Duration
1010
}
1111

12-
func NewDurationJSON(v interface{}) (DurationJSON, error) {
12+
func NewDurationJSON(v any) (DurationJSON, error) {
1313
switch v := v.(type) {
1414
case Duration:
1515
return DurationJSON{Duration: v}, nil
@@ -36,7 +36,7 @@ func NewDurationJSON(v interface{}) (DurationJSON, error) {
3636
}
3737
}
3838

39-
func NewDurationJSONOrPanic(v interface{}) DurationJSON {
39+
func NewDurationJSONOrPanic(v any) DurationJSON {
4040
d, err := NewDurationJSON(v)
4141
if err != nil {
4242
panic(err)
@@ -49,7 +49,7 @@ func (d DurationJSON) MarshalJSON() ([]byte, error) {
4949
}
5050

5151
func (d *DurationJSON) UnmarshalJSON(b []byte) error {
52-
var v interface{}
52+
var v any
5353
var err error
5454

5555
if err = json.Unmarshal(b, &v); err != nil {

internal/holsterv4/clock/duration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestDurationSuite(t *testing.T) {
1717
}
1818

1919
func (s *DurationSuite) TestNewOk() {
20-
for _, v := range []interface{}{
20+
for _, v := range []any{
2121
42 * clock.Second,
2222
int(42000000000),
2323
int64(42000000000),
@@ -33,7 +33,7 @@ func (s *DurationSuite) TestNewOk() {
3333

3434
func (s *DurationSuite) TestNewError() {
3535
for _, tc := range []struct {
36-
v interface{}
36+
v any
3737
errMsg string
3838
}{{
3939
v: "foo",

internal/holsterv4/clock/rfc822_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func TestRFC822Unmarshaling(t *testing.T) {
118118
tcDesc := fmt.Sprintf("Test case #%d: %v", i, tc)
119119
var ts testStruct
120120

121-
inEncoded := []byte(fmt.Sprintf(`{"ts":"%s"}`, tc.inRFC822))
121+
inEncoded := fmt.Appendf(nil, `{"ts":"%s"}`, tc.inRFC822)
122122
err := json.Unmarshal(inEncoded, &ts)
123123
assert.NoError(t, err, tcDesc)
124124
assert.Equal(t, tc.outRFC3339, ts.Time.Format(RFC3339), tcDesc)

internal/holsterv4/collections/priority_queue.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
77
8-
http://www.apache.org/licenses/LICENSE-2.0
8+
http://www.apache.org/licenses/LICENSE-2.0
99
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,7 +21,7 @@ import (
2121

2222
// An PQItem is something we manage in a priority queue.
2323
type PQItem struct {
24-
Value interface{}
24+
Value any
2525
Priority int // The priority of the item in the queue.
2626
// The index is needed by update and is maintained by the heap.Interface methods.
2727
index int // The index of the item in the heap.
@@ -79,14 +79,14 @@ func (mh pqImpl) Swap(i, j int) {
7979
mh[j].index = j
8080
}
8181

82-
func (mh *pqImpl) Push(x interface{}) {
82+
func (mh *pqImpl) Push(x any) {
8383
n := len(*mh)
8484
item := x.(*PQItem)
8585
item.index = n
8686
*mh = append(*mh, item)
8787
}
8888

89-
func (mh *pqImpl) Pop() interface{} {
89+
func (mh *pqImpl) Pop() any {
9090
old := *mh
9191
n := len(old)
9292
item := old[n-1]

internal/holsterv4/collections/priority_queue_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import (
2323
"github.com/vulcand/oxy/v2/internal/holsterv4/collections"
2424
)
2525

26-
func toPtr(i int) interface{} {
26+
func toPtr(i int) any {
2727
return &i
2828
}
2929

30-
func toInt(i interface{}) int {
30+
func toInt(i any) int {
3131
return *(i.(*int))
3232
}
3333

internal/holsterv4/collections/ttlmap.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
type TTLMap struct {
2727
// Optionally specifies a callback function to be
2828
// executed when an entry has expired
29-
OnExpire func(key string, i interface{})
29+
OnExpire func(key string, i any)
3030

3131
capacity int
3232
elements map[string]*mapElement
@@ -36,7 +36,7 @@ type TTLMap struct {
3636

3737
type mapElement struct {
3838
key string
39-
value interface{}
39+
value any
4040
heapEl *PQItem
4141
}
4242

@@ -53,7 +53,7 @@ func NewTTLMap(capacity int) *TTLMap {
5353
}
5454
}
5555

56-
func (m *TTLMap) Set(key string, value interface{}, ttlSeconds int) error {
56+
func (m *TTLMap) Set(key string, value any, ttlSeconds int) error {
5757
expiryTime, err := m.toEpochSeconds(ttlSeconds)
5858
if err != nil {
5959
return err
@@ -69,7 +69,7 @@ func (m *TTLMap) Len() int {
6969
return len(m.elements)
7070
}
7171

72-
func (m *TTLMap) Get(key string) (interface{}, bool) {
72+
func (m *TTLMap) Get(key string) (any, bool) {
7373
value, mapEl, expired := m.lockNGet(key)
7474
if mapEl == nil {
7575
return nil, false
@@ -118,7 +118,7 @@ func (m *TTLMap) GetInt(key string) (int, bool, error) {
118118
return value, true, nil
119119
}
120120

121-
func (m *TTLMap) set(key string, value interface{}, expiryTime int) error {
121+
func (m *TTLMap) set(key string, value any, expiryTime int) error {
122122
if mapEl, ok := m.elements[key]; ok {
123123
mapEl.value = value
124124
m.expiryTimes.Update(mapEl.heapEl, expiryTime)
@@ -142,7 +142,7 @@ func (m *TTLMap) set(key string, value interface{}, expiryTime int) error {
142142
return nil
143143
}
144144

145-
func (m *TTLMap) lockNGet(key string) (value interface{}, mapEl *mapElement, expired bool) {
145+
func (m *TTLMap) lockNGet(key string) (value any, mapEl *mapElement, expired bool) {
146146
m.mutex.RLock()
147147
defer m.mutex.RUnlock()
148148

internal/holsterv4/collections/ttlmap_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,9 @@ func (s *TTLMapSuite) TestUpdate() {
312312
func (s *TTLMapSuite) TestCallOnExpire() {
313313
var called bool
314314
var key string
315-
var val interface{}
315+
var val any
316316
m := NewTTLMap(1)
317-
m.OnExpire = func(k string, el interface{}) {
317+
m.OnExpire = func(k string, el any) {
318318
called = true
319319
key = k
320320
val = el

0 commit comments

Comments
 (0)