More idioms related to go 1.26

This commit is contained in:
9seconds
2026-02-17 23:38:12 +01:00
parent 80b9159ce9
commit 3b03c4a90a
21 changed files with 33 additions and 33 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ func NewEventStream(observerFactories []ObserverFactory) EventStream {
chans: make([]chan mtglib.Event, runtime.NumCPU()),
}
for i := 0; i < runtime.NumCPU(); i++ {
for i := range runtime.NumCPU() {
rv.chans[i] = make(chan mtglib.Event, 1)
if len(observerFactories) == 1 {
+2 -2
View File
@@ -20,7 +20,7 @@ type TypeBoolTestSuite struct {
}
func (suite *TypeBoolTestSuite) TestUnmarshalFail() {
testData := []interface{}{
testData := []any{
"",
"np",
"нет",
@@ -29,7 +29,7 @@ func (suite *TypeBoolTestSuite) TestUnmarshalFail() {
}
for _, v := range testData {
data, err := json.Marshal(map[string]interface{}{
data, err := json.Marshal(map[string]any{
"value": v,
})
suite.NoError(err)
+1 -1
View File
@@ -8,5 +8,5 @@ package logger
// commonly used by many 3pp tools. While mtglib itself does not need it, it is
// always a good idea to support it and have a transient end to end logging.
type StdLikeLogger interface {
Printf(format string, args ...interface{})
Printf(format string, args ...any)
}
+1 -1
View File
@@ -8,7 +8,7 @@ func (n noopLogger) Named(_ string) mtglib.Logger { return n }
func (n noopLogger) BindInt(_ string, _ int) mtglib.Logger { return n }
func (n noopLogger) BindStr(_, _ string) mtglib.Logger { return n }
func (n noopLogger) BindJSON(_, _ string) mtglib.Logger { return n }
func (n noopLogger) Printf(_ string, _ ...interface{}) {}
func (n noopLogger) Printf(_ string, _ ...any) {}
func (n noopLogger) Info(_ string) {}
func (n noopLogger) Warning(_ string) {}
func (n noopLogger) Debug(_ string) {}
+1 -1
View File
@@ -78,7 +78,7 @@ func (z *zeroLogContext) BindJSON(name, value string) mtglib.Logger {
}
}
func (z *zeroLogContext) Printf(format string, args ...interface{}) {
func (z *zeroLogContext) Printf(format string, args ...any) {
z.Debug(fmt.Sprintf(format, args...))
}
+1 -1
View File
@@ -249,7 +249,7 @@ type Logger interface {
BindJSON(name, value string) Logger
// Printf is to support log.Logger behavior.
Printf(format string, args ...interface{})
Printf(format string, args ...any)
// Info puts a message about some normal situation.
Info(msg string)
+1 -1
View File
@@ -12,7 +12,7 @@ func (n NoopLogger) Named(_ string) Logger { return n }
func (n NoopLogger) BindInt(_ string, _ int) Logger { return n }
func (n NoopLogger) BindStr(_, _ string) Logger { return n }
func (n NoopLogger) BindJSON(_, _ string) Logger { return n }
func (n NoopLogger) Printf(_ string, _ ...interface{}) {}
func (n NoopLogger) Printf(_ string, _ ...any) {}
func (n NoopLogger) Info(_ string) {}
func (n NoopLogger) Warning(_ string) {}
func (n NoopLogger) Debug(_ string) {}
+1 -1
View File
@@ -76,7 +76,7 @@ func ParseClientHello(secret, handshake []byte) (ClientHello, error) {
computedRandom := mac.Sum(nil)
for i := 0; i < RandomLen; i++ {
for i := range RandomLen {
computedRandom[i] ^= hello.Random[i]
}
+1 -1
View File
@@ -6,7 +6,7 @@ import (
)
var bytesBufferPool = sync.Pool{
New: func() interface{} {
New: func() any {
return &bytes.Buffer{}
},
}
+1 -1
View File
@@ -5,7 +5,7 @@ import (
)
var recordPool = sync.Pool{
New: func() interface{} {
New: func() any {
return &Record{}
},
}
@@ -63,7 +63,7 @@ func (h *handshakeFrame) connectionType() []byte {
func (h *handshakeFrame) invert() handshakeFrame {
copyFrame := *h
for i := 0; i < handshakeFrameLenKey+handshakeFrameLenIV; i++ {
for i := range handshakeFrameLenKey + handshakeFrameLenIV {
copyFrame.data[handshakeFrameOffsetKey+i] = h.data[handshakeFrameOffsetConnectionType-1-i]
}
+1 -1
View File
@@ -117,7 +117,7 @@ func NewServerHandshakeTestData(t *testing.T) ServerHandshakeTestData {
serverEncryptedReverted := make([]byte, len(serverEncrypted))
for i := 0; i < 32+16; i++ {
for i := range 32 + 16 {
serverEncryptedReverted[8+i] = serverEncrypted[8+32+16-1-i]
}
+2 -2
View File
@@ -9,12 +9,12 @@ import (
var (
sha256HasherPool = sync.Pool{
New: func() interface{} {
New: func() any {
return sha256.New()
},
}
bytesBufferPool = sync.Pool{
New: func() interface{} {
New: func() any {
return &bytes.Buffer{}
},
}
+1 -1
View File
@@ -5,5 +5,5 @@ const (
)
type Logger interface {
Printf(msg string, args ...interface{})
Printf(msg string, args ...any)
}
+1 -1
View File
@@ -2,4 +2,4 @@ package relay_test
type loggerMock struct{}
func (l loggerMock) Printf(format string, args ...interface{}) {}
func (l loggerMock) Printf(format string, args ...any) {}
+1 -1
View File
@@ -3,7 +3,7 @@ package relay
import "sync"
var copyBufferPool = sync.Pool{
New: func() interface{} {
New: func() any {
rv := make([]byte, copyBufferSize)
return &rv
+1 -1
View File
@@ -323,7 +323,7 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) {
}
pool, err := ants.NewPoolWithFunc(opts.getConcurrency(),
func(arg interface{}) {
func(arg any) {
proxy.ServeConn(arg.(essentials.Conn)) //nolint: forcetypeassert
},
ants.WithLogger(opts.getLogger("ants")),
+1 -1
View File
@@ -32,7 +32,7 @@ func (s *streamContext) Err() error {
return s.ctx.Err() //nolint: wrapcheck
}
func (s *streamContext) Value(key interface{}) interface{} {
func (s *streamContext) Value(key any) any {
return s.ctx.Value(key)
}
+1 -1
View File
@@ -59,7 +59,7 @@ func (suite *CircuitBreakerTestSuite) TestMultipleRunsOk() {
suite.ctxCancel()
}()
for i := 0; i < 5; i++ {
for range 5 {
go func() {
defer wg.Done()
+1 -1
View File
@@ -64,7 +64,7 @@ func (suite *LoadBalancedSocks5TestSuite) TestCannotDial() {
})
suite.NoError(err)
for i := 0; i < network.ProxyDialerOpenThreshold*2; i++ {
for range network.ProxyDialerOpenThreshold * 2 {
_, err = lbDialer.Dial("tcp", "127.1.1.1:80")
suite.True(errors.Is(err, network.ErrCannotDialWithAllProxies))
}
+1 -1
View File
@@ -3,7 +3,7 @@ package stats
import "sync"
var streamInfoPool = sync.Pool{
New: func() interface{} {
New: func() any {
return &streamInfo{
tags: make(map[string]string),
}