mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-10-29 15:02:30 +00:00
Apply go fix to simplify using modern features
This patch contains the result of running `go fix ./...`, which applies simplifications that make use of modern language features. There are no logic or behaviour changes.
This commit is contained in:
@@ -9,9 +9,9 @@ import (
|
||||
func runBench(b *testing.B, events int) {
|
||||
nTraces := (b.N + events + 1) / events
|
||||
|
||||
for i := 0; i < nTraces; i++ {
|
||||
for range nTraces {
|
||||
tr := New("bench", "test")
|
||||
for j := 0; j < events; j++ {
|
||||
for j := range events {
|
||||
tr.Printf("%d", j)
|
||||
}
|
||||
tr.Finish()
|
||||
|
||||
@@ -53,7 +53,7 @@ func (h *histogram) Snapshot() *histSnapshot {
|
||||
}
|
||||
|
||||
var cumCount uint64
|
||||
for i := 0; i < nBuckets; i++ {
|
||||
for i := range nBuckets {
|
||||
cumCount += h.count[i]
|
||||
l := line{
|
||||
Start: buckets[i],
|
||||
|
||||
@@ -141,7 +141,7 @@ func TestHTTP(t *testing.T) {
|
||||
func TestHTTPLong(t *testing.T) {
|
||||
// Test a long trace.
|
||||
tr := New("TestHTTPLong", "verbose")
|
||||
for i := 0; i < 1000; i++ {
|
||||
for i := range 1000 {
|
||||
tr.Printf("entry #%d", i)
|
||||
}
|
||||
tr.Finish()
|
||||
|
||||
@@ -5,6 +5,7 @@ package nettrace
|
||||
import (
|
||||
"container/ring"
|
||||
"fmt"
|
||||
"maps"
|
||||
"math/rand/v2"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -51,11 +52,11 @@ type Trace interface {
|
||||
SetError()
|
||||
|
||||
// Printf adds a message to the trace.
|
||||
Printf(format string, a ...interface{})
|
||||
Printf(format string, a ...any)
|
||||
|
||||
// Errorf adds a message to the trace, marks it as an error, and returns
|
||||
// an error for it.
|
||||
Errorf(format string, a ...interface{}) error
|
||||
Errorf(format string, a ...any) error
|
||||
|
||||
// Finish marks the trace as complete.
|
||||
// The trace should not be used after calling this method.
|
||||
@@ -220,7 +221,7 @@ func (tr *trace) SetError() {
|
||||
tr.mu.Unlock()
|
||||
}
|
||||
|
||||
func (tr *trace) Printf(format string, a ...interface{}) {
|
||||
func (tr *trace) Printf(format string, a ...any) {
|
||||
evt := &event{
|
||||
When: time.Now(),
|
||||
Type: evtLOG,
|
||||
@@ -230,7 +231,7 @@ func (tr *trace) Printf(format string, a ...interface{}) {
|
||||
tr.append(evt)
|
||||
}
|
||||
|
||||
func (tr *trace) Errorf(format string, a ...interface{}) error {
|
||||
func (tr *trace) Errorf(format string, a ...any) error {
|
||||
tr.SetError()
|
||||
err := fmt.Errorf(format, a...)
|
||||
tr.Printf("%s", err.Error())
|
||||
@@ -354,7 +355,7 @@ func (r *traceRing) Len() int {
|
||||
}
|
||||
|
||||
func (r *traceRing) Do(f func(tr *trace)) {
|
||||
r.ring.Do(func(x interface{}) {
|
||||
r.ring.Do(func(x any) {
|
||||
if x == nil {
|
||||
return
|
||||
}
|
||||
@@ -382,7 +383,7 @@ type familyTraces struct {
|
||||
func newFamilyTraces() *familyTraces {
|
||||
ft := &familyTraces{}
|
||||
ft.active = map[id]*trace{}
|
||||
for i := 0; i < nBuckets; i++ {
|
||||
for i := range nBuckets {
|
||||
ft.finished[i] = newTraceRing(tracesInBucket)
|
||||
}
|
||||
ft.errors = newTraceRing(tracesInBucket)
|
||||
@@ -512,9 +513,7 @@ func copyFamilies() map[string]*familyTraces {
|
||||
n := map[string]*familyTraces{}
|
||||
|
||||
familiesMu.Lock()
|
||||
for f, trs := range families {
|
||||
n[f] = trs
|
||||
}
|
||||
maps.Copy(n, families)
|
||||
familiesMu.Unlock()
|
||||
|
||||
return n
|
||||
|
||||
@@ -37,13 +37,13 @@ func TestLong(t *testing.T) {
|
||||
tr.SetMaxEvents(100)
|
||||
|
||||
// First 90 events, no drop.
|
||||
for i := 0; i < 90; i++ {
|
||||
for i := range 90 {
|
||||
tr.Printf("evt %d", i)
|
||||
}
|
||||
expectEvents(t, tr, 90)
|
||||
|
||||
// Up to 99, still no drop.
|
||||
for i := 0; i < 9; i++ {
|
||||
for i := range 9 {
|
||||
tr.Printf("evt %d", i)
|
||||
}
|
||||
expectEvents(t, tr, 99)
|
||||
@@ -57,7 +57,7 @@ func TestLong(t *testing.T) {
|
||||
expectEvents(t, tr, 101)
|
||||
|
||||
// Add more events, expect none of them to exceed 101.
|
||||
for i := 0; i < 9; i++ {
|
||||
for i := range 9 {
|
||||
tr.Printf("evt %d", i)
|
||||
expectEvents(t, tr, 101)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user