Run modernize to rewrite some older go constructs to newer ones

Mostly using slice.Sort, using min/max, slices.Concat, range of int and
fmt.Appendf for byte slices instead of strings.
This commit is contained in:
Mechiel Lukkien
2025-03-06 17:33:06 +01:00
parent f6132bdbc0
commit 64f2f788b1
61 changed files with 146 additions and 232 deletions

View File

@ -55,7 +55,7 @@ func (l *Limiter) checkAdd(add bool, ip net.IP, tm time.Time, n int64) bool {
l.WindowLimits[i].Counts = pl.Counts
}
for j := 0; j < 3; j++ {
for j := range 3 {
if i == 0 {
l.ipmasked[j] = l.maskIP(j, ip)
}
@ -74,7 +74,7 @@ func (l *Limiter) checkAdd(add bool, ip net.IP, tm time.Time, n int64) bool {
}
// Finally record.
for _, pl := range l.WindowLimits {
for j := 0; j < 3; j++ {
for j := range 3 {
pl.Counts[struct {
Index uint8
IPMasked [16]byte
@ -90,7 +90,7 @@ func (l *Limiter) Reset(ip net.IP, tm time.Time) {
defer l.Unlock()
// Prepare masked ip's.
for i := 0; i < 3; i++ {
for i := range 3 {
l.ipmasked[i] = l.maskIP(i, ip)
}
@ -100,7 +100,7 @@ func (l *Limiter) Reset(ip net.IP, tm time.Time) {
continue
}
var n int64
for j := 0; j < 3; j++ {
for j := range 3 {
k := struct {
Index uint8
IPMasked [16]byte