chore: linter: intrange

Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
Jakob Borg
2025-10-21 08:36:42 +02:00
parent 465804161b
commit a1069a0d70
16 changed files with 22 additions and 22 deletions

View File

@@ -162,7 +162,7 @@ func main() {
testCert = createTestCertificate() testCert = createTestCertificate()
for i := 0; i < requestProcessors; i++ { for range requestProcessors {
go requestProcessor(geoip) go requestProcessor(geoip)
} }

View File

@@ -47,7 +47,7 @@ func newMetricsSet(srv *server) *metricsSet {
var initForType func(reflect.Type) var initForType func(reflect.Type)
initForType = func(t reflect.Type) { initForType = func(t reflect.Type) {
for i := 0; i < t.NumField(); i++ { for i := range t.NumField() {
field := t.Field(i) field := t.Field(i)
if field.Type.Kind() == reflect.Struct { if field.Type.Kind() == reflect.Struct {
initForType(field.Type) initForType(field.Type)
@@ -175,7 +175,7 @@ func (s *metricsSet) addReport(r *contract.Report) {
func (s *metricsSet) addReportStruct(v reflect.Value, gaugeVecs map[string][]string) { func (s *metricsSet) addReportStruct(v reflect.Value, gaugeVecs map[string][]string) {
t := v.Type() t := v.Type()
for i := 0; i < v.NumField(); i++ { for i := range v.NumField() {
field := v.Field(i) field := v.Field(i)
if field.Kind() == reflect.Struct { if field.Kind() == reflect.Struct {
s.addReportStruct(field, gaugeVecs) s.addReportStruct(field, gaugeVecs)

View File

@@ -122,7 +122,7 @@ func (r *rateCalculator) updateRates(interval time.Duration) {
func (r *rateCalculator) rate(periods int) int64 { func (r *rateCalculator) rate(periods int) int64 {
var tot int64 var tot int64
for i := 0; i < periods; i++ { for i := range periods {
tot += r.rates[i] tot += r.rates[i]
} }
return tot / int64(periods) return tot / int64(periods)

View File

@@ -337,7 +337,7 @@ func formatOptionalPercentS(template string, username string) string {
if nReps < 0 { if nReps < 0 {
nReps = 0 nReps = 0
} }
for i := 0; i < nReps; i++ { for range nReps {
replacements = append(replacements, username) replacements = append(replacements, username)
} }
return fmt.Sprintf(template, replacements...) return fmt.Sprintf(template, replacements...)

View File

@@ -684,7 +684,7 @@ func copyMatchingTag(from interface{}, to interface{}, tag string, shouldCopy fu
panic(fmt.Sprintf("non equal types: %s != %s", fromType, toType)) panic(fmt.Sprintf("non equal types: %s != %s", fromType, toType))
} }
for i := 0; i < toStruct.NumField(); i++ { for i := range toStruct.NumField() {
fromField := fromStruct.Field(i) fromField := fromStruct.Field(i)
toField := toStruct.Field(i) toField := toStruct.Field(i)

View File

@@ -524,7 +524,7 @@ func (s *bufferedSubscription) Since(id int, into []Event, timeout time.Duration
into = append(into, s.buf[i]) into = append(into, s.buf[i])
} }
} }
for i := 0; i < s.next; i++ { for i := range s.next {
if s.buf[i].SubscriptionID > id { if s.buf[i].SubscriptionID > id {
into = append(into, s.buf[i]) into = append(into, s.buf[i])
} }

View File

@@ -356,7 +356,7 @@ func (s *Service) tryNATDevice(ctx context.Context, natd Device, intAddr Address
l.Debugf("Error extending lease on %v (external port %d -> internal port %d): %v", natd.ID(), extPort, intAddr.Port, err) l.Debugf("Error extending lease on %v (external port %d -> internal port %d): %v", natd.ID(), extPort, intAddr.Port, err)
} }
for i := 0; i < 10; i++ { for range 10 {
select { select {
case <-ctx.Done(): case <-ctx.Done():
return []Address{}, ctx.Err() return []Address{}, ctx.Err()

View File

@@ -48,7 +48,7 @@ func nextSuffix() string {
// to remove the file when no longer needed. // to remove the file when no longer needed.
func TempFile(filesystem fs.Filesystem, dir, prefix string) (f fs.File, err error) { func TempFile(filesystem fs.Filesystem, dir, prefix string) (f fs.File, err error) {
nconflict := 0 nconflict := 0
for i := 0; i < 10000; i++ { for range 10000 {
name := filepath.Join(dir, prefix+nextSuffix()) name := filepath.Join(dir, prefix+nextSuffix())
f, err = filesystem.OpenFile(name, fs.OptReadWrite|fs.OptCreate|fs.OptExclusive, 0o600) f, err = filesystem.OpenFile(name, fs.OptReadWrite|fs.OptCreate|fs.OptExclusive, 0o600)
if fs.IsExist(err) { if fs.IsExist(err) {

View File

@@ -181,7 +181,7 @@ func luhnify(s string) (string, error) {
} }
res := make([]byte, 4*(13+1)) res := make([]byte, 4*(13+1))
for i := 0; i < 4; i++ { for i := range 4 {
p := s[i*13 : (i+1)*13] p := s[i*13 : (i+1)*13]
copy(res[i*(13+1):], p) copy(res[i*(13+1):], p)
l, err := luhn32(p) l, err := luhn32(p)
@@ -199,7 +199,7 @@ func unluhnify(s string) (string, error) {
} }
res := make([]byte, 52) res := make([]byte, 52)
for i := 0; i < 4; i++ { for i := range 4 {
p := s[i*(13+1) : (i+1)*(13+1)-1] p := s[i*(13+1) : (i+1)*(13+1)-1]
copy(res[i*13:], p) copy(res[i*13:], p)
l, err := luhn32(p) l, err := luhn32(p)
@@ -216,7 +216,7 @@ func unluhnify(s string) (string, error) {
func chunkify(s string) string { func chunkify(s string) string {
chunks := len(s) / 7 chunks := len(s) / 7
res := make([]byte, chunks*(7+1)-1) res := make([]byte, chunks*(7+1)-1)
for i := 0; i < chunks; i++ { for i := range chunks {
if i > 0 { if i > 0 {
res[i*(7+1)-1] = '-' res[i*(7+1)-1] = '-'
} }

View File

@@ -41,7 +41,7 @@ func String(l int) string {
var sb strings.Builder var sb strings.Builder
sb.Grow(l) sb.Grow(l)
for i := 0; i < l; i++ { for range l {
sb.WriteByte(randomCharset[defaultSecureRand.Intn(len(randomCharset))]) sb.WriteByte(randomCharset[defaultSecureRand.Intn(len(randomCharset))])
} }
return sb.String() return sb.String()

View File

@@ -132,7 +132,7 @@ func TestRelay(ctx context.Context, uri *url.URL, certs []tls.Certificate, sleep
}() }()
defer cancel() defer cancel()
for i := 0; i < times; i++ { for range times {
_, err = GetInvitationFromRelay(ctx, uri, id, certs, timeout) _, err = GetInvitationFromRelay(ctx, uri, id, certs, timeout)
if err == nil { if err == nil {
return nil return nil

View File

@@ -84,7 +84,7 @@ func newParallelHasher(ctx context.Context, folderID string, fs fs.Filesystem, w
} }
ph.wg.Add(workers) ph.wg.Add(workers)
for i := 0; i < workers; i++ { for range workers {
go ph.hashFiles(ctx) go ph.hashFiles(ctx)
} }

View File

@@ -93,7 +93,7 @@ func FillNil(data any) {
func fillNil(data any, skipDeprecated bool) { func fillNil(data any, skipDeprecated bool) {
s := reflect.ValueOf(data).Elem() s := reflect.ValueOf(data).Elem()
t := s.Type() t := s.Type()
for i := 0; i < s.NumField(); i++ { for i := range s.NumField() {
if skipDeprecated && strings.HasPrefix(t.Field(i).Name, "Deprecated") { if skipDeprecated && strings.HasPrefix(t.Field(i).Name, "Deprecated") {
continue continue
} }
@@ -123,7 +123,7 @@ func fillNil(data any, skipDeprecated bool) {
if f.Type().Elem().Kind() != reflect.Struct { if f.Type().Elem().Kind() != reflect.Struct {
continue continue
} }
for i := 0; i < f.Len(); i++ { for i := range f.Len() {
fillNil(f.Index(i).Addr().Interface(), skipDeprecated) fillNil(f.Index(i).Addr().Interface(), skipDeprecated)
} }
case reflect.Struct: case reflect.Struct:
@@ -142,7 +142,7 @@ func FillNilSlices(data any) error {
s := reflect.ValueOf(data).Elem() s := reflect.ValueOf(data).Elem()
t := s.Type() t := s.Type()
for i := 0; i < s.NumField(); i++ { for i := range s.NumField() {
f := s.Field(i) f := s.Field(i)
tag := t.Field(i).Tag tag := t.Field(i).Tag

View File

@@ -119,7 +119,7 @@ func CompareVersions(a, b string) Relation {
} }
// First compare major-minor-patch versions // First compare major-minor-patch versions
for i := 0; i < minlen; i++ { for i := range minlen {
if arel[i] < brel[i] { if arel[i] < brel[i] {
if i == 0 { if i == 0 {
// major version difference // major version difference
@@ -168,7 +168,7 @@ func CompareVersions(a, b string) Relation {
} }
// Compare prerelease strings // Compare prerelease strings
for i := 0; i < minlen; i++ { for i := range minlen {
switch av := apre[i].(type) { switch av := apre[i].(type) {
case int: case int:
switch bv := bpre[i].(type) { switch bv := bpre[i].(type) {

View File

@@ -249,7 +249,7 @@ func clear(v interface{}, since int) error {
s := reflect.ValueOf(v).Elem() s := reflect.ValueOf(v).Elem()
t := s.Type() t := s.Type()
for i := 0; i < s.NumField(); i++ { for i := range s.NumField() {
f := s.Field(i) f := s.Field(i)
tag := t.Field(i).Tag tag := t.Field(i).Tag

View File

@@ -436,7 +436,7 @@ func CpuBench(ctx context.Context, iterations int, duration time.Duration) float
r.Read(bs) r.Read(bs)
var perf float64 var perf float64
for i := 0; i < iterations; i++ { for range iterations {
if v := cpuBenchOnce(ctx, duration, bs); v > perf { if v := cpuBenchOnce(ctx, duration, bs); v > perf {
perf = v perf = v
} }