Skip to content

Conversation

@meshenka
Copy link
Contributor

@meshenka meshenka commented Nov 4, 2025

Upgrade to Go 1.25 and fix Go 1.22+ linting issues

Upgrade Summary

This PR upgrades the codebase from Go 1.18 to Go 1.25 and fixes linting issues introduced by new Go 1.22+ linters.

Changes

Go Version Upgrade

  • Updated go.mod from go 1.18 to go 1.25
  • Ran go mod tidy to update dependencies

Go 1.22+ Linting Fixes

copyloopvar (4 fixes):

  • Removed unnecessary loop variable copies in closures
  • In Go 1.22+, loop variables are automatically captured correctly, making explicit copies redundant
  • Fixed in:
    • main.go: Removed copies of idxName, shards, and i in initScrollers()
    • scroll.go: Removed copy of scroller in scroll()

intrange (1 fix):

  • Changed traditional for loop to use integer range syntax
  • for i := 0; i < slices; i++for i := range slices
  • More idiomatic Go 1.22+ syntax

Files Modified

  • go.mod - Updated Go version
  • main.go - Removed loop variable copies, used integer range
  • scroll.go - Removed loop variable copy

Benefits

  • Modern Go syntax: Uses Go 1.22+ features for cleaner code
  • Improved performance: Removed unnecessary variable copies
  • Better maintainability: More idiomatic Go code
  • Linter compliance: All new Go 1.22+ linters satisfied

@meshenka meshenka force-pushed the feat/add-test-coverage branch 2 times, most recently from 8bd3189 to 12ccac3 Compare November 18, 2025 13:00
@meshenka meshenka force-pushed the feat/add-test-coverage branch from 12ccac3 to 5a5a5fe Compare November 18, 2025 13:37
@meshenka meshenka marked this pull request as ready for review November 18, 2025 13:38
@meshenka
Copy link
Contributor Author

could be nice to enable github workflows

🎉

@meshenka
Copy link
Contributor Author

up @hchargois :D

@meshenka
Copy link
Contributor Author

🙏 @hchargois

Copy link
Owner

@hchargois hchargois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!

Sorry for taking so much time to answer.

First I'd like to thank you sincerely for your interest in my little project and for your contributions!

There are quite a few your tests that don't actually test esdump at all; I think these should be removed. If you really want to have tests, some functions could be extracted so they can be unit tested; as I've done for the flag validation for example.

But otherwise, I'd rather keep tests lean and focused; the less the better. Most of the tricky behavior would only be exercised by testing with a real ES cluster anyway.

Thanks again.

Comment on lines +73 to +78
var transport *http.Transport
if defaultTransport, ok := http.DefaultTransport.(*http.Transport); ok {
transport = defaultTransport.Clone()
} else {
transport = &http.Transport{}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary, DefaultTransport is never going to change, a bare type assert is fine

Comment on lines +83 to +85
transport.TLSClientConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good idea, this should be left unset so that the (safe) default is used.

Comment on lines +288 to +298
const maxInt32 = int32(^uint32(0) >> 1)
scrollersLen := len(scrollers)
if scrollersLen > 0 && scrollersLen <= int(maxInt32) {
if scrollersLen <= int(^int32(0)>>1) {
d.totalHitsPending = int32(scrollersLen)
} else {
d.totalHitsPending = maxInt32
}
} else {
d.totalHitsPending = maxInt32
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is technically necessary to prevent overflows that can't really happen anyway... That made me rethink the use of atomics in the first place (which impose those sized ints); I've changed that for a cleaner dedicated thread safe counter.

}
}

func TestIPIsLoopback(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove

@@ -0,0 +1,309 @@
package main
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove, none of these tests are testing esdump?

"github.com/stretchr/testify/require"
)

func TestScrollQuery_JSONMarshaling(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove

assert.InDelta(t, float64(5), slice["max"], 0.01, "slice max should be 5")
}

func TestSleepForThrottling(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing sleep durations is inherently brittle, a possible solution would be to use the new synctest package to freeze time. But a much simpler solution is not to test the actual sleep; the important thing to test is the value of the computed duration; for that reason I've extracted that logic into its own function.

@@ -0,0 +1,156 @@
package main
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove

@@ -0,0 +1,51 @@
name: golang
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not have github workflows, I don't know what half of this does and I find it cumbersome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants