Skip to content

Commit 0bd2663

Browse files
authored
Run modernize (#412)
`go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...`
1 parent 042a9fc commit 0bd2663

19 files changed

Lines changed: 48 additions & 68 deletions

api/api.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ type Server struct {
6767
updates chan<- aggregate.UpdateReq
6868

6969
// Parent loggers
70-
infoln func(data ...interface{})
71-
errorln func(data ...interface{})
70+
infoln func(data ...any)
71+
errorln func(data ...any)
7272
status BenchmarkStatus
7373
cmdLine string
7474

@@ -110,7 +110,7 @@ func (s *Server) SetUpdate(updates chan<- aggregate.UpdateReq) {
110110

111111
// SetLnLoggers can be used to set upstream loggers.
112112
// When logging to the servers these will be called.
113-
func (s *Server) SetLnLoggers(info, err func(data ...interface{})) {
113+
func (s *Server) SetLnLoggers(info, err func(data ...any)) {
114114
s.mu.Lock()
115115
s.infoln = info
116116
s.errorln = err
@@ -129,7 +129,7 @@ func (s *Server) Done() {
129129

130130
// InfoLn allows to log data to the server.
131131
// The server will update its status and send message upstream if set.
132-
func (s *Server) InfoLn(data ...interface{}) {
132+
func (s *Server) InfoLn(data ...any) {
133133
s.mu.Lock()
134134
defer s.mu.Unlock()
135135
if s.infoln != nil {
@@ -140,14 +140,14 @@ func (s *Server) InfoLn(data ...interface{}) {
140140

141141
// InfoQuietln can be used to log data to the internal status only
142142
// and not forward it to the upstream logger.
143-
func (s *Server) InfoQuietln(data ...interface{}) {
143+
func (s *Server) InfoQuietln(data ...any) {
144144
s.mu.Lock()
145145
s.status.LastStatus = strings.TrimSpace(fmt.Sprintln(data...))
146146
s.mu.Unlock()
147147
}
148148

149149
// Errorln allows to store a non-fatal error.
150-
func (s *Server) Errorln(data ...interface{}) {
150+
func (s *Server) Errorln(data ...any) {
151151
s.mu.Lock()
152152
defer s.mu.Unlock()
153153
if s.errorln != nil {

cli/analyze.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func mainAnalyze(ctx *cli.Context) error {
122122
}
123123
monitor := api.NewBenchmarkMonitor(ctx.String(serverFlagName), nil)
124124
defer monitor.Done()
125-
log := func(format string, data ...interface{}) {
125+
log := func(format string, data ...any) {
126126
console.Eraseline()
127127
console.Printf("\r"+format, data...)
128128
}

cli/benchclient.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,7 @@ func serveWs(w http.ResponseWriter, r *http.Request) {
230230
ab.info[req.Stage] = info
231231
ab.Unlock()
232232

233-
wait := time.Until(req.StartTime)
234-
if wait < 0 {
235-
wait = 0
236-
}
233+
wait := max(time.Until(req.StartTime), 0)
237234
console.Infoln("Starting stage", req.Stage, "in", wait)
238235
go func() {
239236
time.Sleep(wait)

cli/benchmark.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func runBench(ctx *cli.Context, b bench.Benchmark) error {
133133
c.UpdateStatus = ui.SetSubText
134134

135135
monitor := api.NewBenchmarkMonitor(ctx.String(serverFlagName), updates)
136-
monitor.SetLnLoggers(func(data ...interface{}) {
136+
monitor.SetLnLoggers(func(data ...any) {
137137
ui.SetSubText(strings.TrimRight(fmt.Sprintln(data...), "\r\n."))
138138
}, printError)
139139
defer monitor.Done()
@@ -613,8 +613,8 @@ func checkBenchmark(ctx *cli.Context) {
613613
_, err := parseInfluxURL(ctx)
614614
fatalIf(probe.NewError(err), "invalid influx config")
615615

616-
profs := strings.Split(ctx.String("serverprof"), ",")
617-
for _, profilerType := range profs {
616+
profs := strings.SplitSeq(ctx.String("serverprof"), ",")
617+
for profilerType := range profs {
618618
if len(profilerType) == 0 {
619619
continue
620620
}

cli/benchserver.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"encoding/json"
2323
"errors"
2424
"fmt"
25+
"maps"
2526
"net/url"
2627
"os"
2728
"strconv"
@@ -112,7 +113,7 @@ func runServerBenchmark(ctx *cli.Context, b bench.Benchmark) (bool, error) {
112113
if len(conns.hosts) == 0 {
113114
return true, errors.New("no hosts")
114115
}
115-
infoLn := func(data ...interface{}) {
116+
infoLn := func(data ...any) {
116117
ui.SetSubText(strings.TrimRight(fmt.Sprintln(data...), "\r\n."))
117118
}
118119

@@ -174,9 +175,7 @@ func runServerBenchmark(ctx *cli.Context, b bench.Benchmark) (bool, error) {
174175
}
175176
}
176177
}
177-
for k, v := range b.GetCommon().ExtraFlags {
178-
req.Benchmark.Flags[k] = v
179-
}
178+
maps.Copy(req.Benchmark.Flags, b.GetCommon().ExtraFlags)
180179

181180
// Connect to hosts, send benchmark requests.
182181
ui.StartPrepare("Preparing", nil, nil)
@@ -349,8 +348,8 @@ func runServerBenchmark(ctx *cli.Context, b bench.Benchmark) (bool, error) {
349348

350349
// connections keeps track of connections to clients.
351350
type connections struct {
352-
info func(data ...interface{})
353-
errLn func(data ...interface{})
351+
info func(data ...any)
352+
errLn func(data ...any)
354353
hosts []string
355354
ws []*websocket.Conn
356355
si serverInfo
@@ -369,7 +368,7 @@ func newConnections(hosts []string) *connections {
369368
return &c
370369
}
371370

372-
func (c *connections) errorF(format string, data ...interface{}) {
371+
func (c *connections) errorF(format string, data ...any) {
373372
c.errLn(fmt.Sprintf(format, data...))
374373
}
375374

@@ -700,9 +699,7 @@ func (c *connections) waitForStage(ctx context.Context, stage benchmarkStage, fa
700699
if common.Custom == nil {
701700
common.Custom = make(map[string]string, len(resp.StageInfo.Custom))
702701
}
703-
for k, v := range resp.StageInfo.Custom {
704-
common.Custom[k] = v
705-
}
702+
maps.Copy(common.Custom, resp.StageInfo.Custom)
706703
mu.Unlock()
707704
}
708705
c.info("Client", c.hostName(i), ": Finished stage", stage, "...")

cli/complete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var completeCmds = map[string]complete.Predictor{
5555
func flagsToCompleteFlags(flags []cli.Flag) complete.Flags {
5656
complFlags := make(complete.Flags)
5757
for _, f := range flags {
58-
for _, s := range strings.Split(f.GetName(), ",") {
58+
for s := range strings.SplitSeq(f.GetName(), ",") {
5959
var flagName string
6060
s = strings.TrimSpace(s)
6161
if len(s) == 1 {

cli/print.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type errorMessage struct {
4646

4747
var printMu sync.Mutex
4848

49-
func printError(data ...interface{}) {
49+
func printError(data ...any) {
5050
printMu.Lock()
5151
defer printMu.Unlock()
5252
w, _ := pb.GetTerminalWidth()
@@ -59,14 +59,14 @@ func printError(data ...interface{}) {
5959
}
6060

6161
// fatalIf wrapper function which takes error and selectively prints stack frames if available on debug
62-
func fatalIf(err *probe.Error, msg string, data ...interface{}) {
62+
func fatalIf(err *probe.Error, msg string, data ...any) {
6363
if err == nil {
6464
return
6565
}
6666
fatal(err, msg, data...)
6767
}
6868

69-
func fatal(err *probe.Error, msg string, data ...interface{}) {
69+
func fatal(err *probe.Error, msg string, data ...any) {
7070
if globalJSON {
7171
errorMsg := errorMessage{
7272
Message: msg,
@@ -125,7 +125,7 @@ func fatal(err *probe.Error, msg string, data ...interface{}) {
125125
}
126126

127127
// errorIf synonymous with fatalIf but doesn't exit on error != nil
128-
func errorIf(err *probe.Error, msg string, data ...interface{}) {
128+
func errorIf(err *probe.Error, msg string, data ...any) {
129129
if err == nil {
130130
return
131131
}

cli/snowball.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ func mainSnowball(ctx *cli.Context) error {
7575
if err != nil {
7676
return err
7777
}
78-
b.WindowSize = int(sz) * 2
79-
if b.WindowSize < 128<<10 {
80-
b.WindowSize = 128 << 10
81-
}
78+
b.WindowSize = max(int(sz)*2, 128<<10)
8279
if b.WindowSize > 16<<20 {
8380
b.WindowSize = 16 << 20
8481
}

cli/ui.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ func (u *ui) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
111111
u.quitPls.Store(true)
112112
return u, tea.Batch(tea.ShowCursor, tea.Quit)
113113
case tea.WindowSizeMsg:
114-
u.progress.Width = msg.Width - 4
115-
if u.progress.Width > maxWidth-padding {
116-
u.progress.Width = maxWidth - padding
117-
}
114+
u.progress.Width = min(msg.Width-4, maxWidth-padding)
118115
case tickMsg:
119116
batch := []tea.Cmd{tickCmd()}
120117
u.showProgress = false

pkg/aggregate/live.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"bytes"
2222
"fmt"
2323
"io"
24+
"maps"
2425
"math/bits"
2526
"slices"
2627
"sort"
@@ -165,9 +166,7 @@ func (l *LiveAggregate) Merge(l2 LiveAggregate) {
165166
l.Requests = make(map[string]RequestSegments)
166167
}
167168
if len(l2.Requests) > 0 {
168-
for k, v := range l2.Requests {
169-
l.Requests[k] = v
170-
}
169+
maps.Copy(l.Requests, l2.Requests)
171170
}
172171
l.Concurrency += l2.Concurrency
173172
l.TotalBytes += l2.TotalBytes
@@ -277,8 +276,8 @@ type ReportOptions struct {
277276
OnlyOps map[string]struct{}
278277
}
279278

280-
func (o ReportOptions) printfColor(dst io.Writer) func(ca color.Attribute, format string, args ...interface{}) {
281-
return func(ca color.Attribute, format string, args ...interface{}) {
279+
func (o ReportOptions) printfColor(dst io.Writer) func(ca color.Attribute, format string, args ...any) {
280+
return func(ca color.Attribute, format string, args ...any) {
282281
if !o.Color {
283282
fmt.Fprintf(dst, format, args...)
284283
return
@@ -287,7 +286,7 @@ func (o ReportOptions) printfColor(dst io.Writer) func(ca color.Attribute, forma
287286
}
288287
}
289288

290-
func (o ReportOptions) printf(ca color.Attribute, format string, args ...interface{}) string {
289+
func (o ReportOptions) printf(ca color.Attribute, format string, args ...any) string {
291290
if !o.Color {
292291
return fmt.Sprintf(format, args...)
293292
}

0 commit comments

Comments
 (0)