Skip to content

Commit 08ceeb1

Browse files
authored
*: run go fix (#2689)
Excluded: - components/playground-ng/daemon_mode.go becuse of golang/go#77671
1 parent 908be86 commit 08ceeb1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+100
-140
lines changed

components/cluster/command/root.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,20 @@ func printErrorMessageForNormalError(err error) {
190190
}
191191

192192
func printErrorMessageForErrorX(err *errorx.Error) {
193-
msg := ""
193+
var msg strings.Builder
194194
ident := 0
195195
causeErrX := err
196196
for causeErrX != nil {
197197
if ident > 0 {
198-
msg += strings.Repeat(" ", ident) + "caused by: "
198+
msg.WriteString(strings.Repeat(" ", ident) + "caused by: ")
199199
}
200200
currentErrMsg := causeErrX.Message()
201201
if len(currentErrMsg) > 0 {
202202
if ident == 0 {
203203
// Print error code only for top level error
204-
msg += fmt.Sprintf("%s (%s)\n", currentErrMsg, causeErrX.Type().FullName())
204+
msg.WriteString(fmt.Sprintf("%s (%s)\n", currentErrMsg, causeErrX.Type().FullName()))
205205
} else {
206-
msg += fmt.Sprintf("%s\n", currentErrMsg)
206+
msg.WriteString(fmt.Sprintf("%s\n", currentErrMsg))
207207
}
208208
ident++
209209
}
@@ -215,14 +215,14 @@ func printErrorMessageForErrorX(err *errorx.Error) {
215215
if ident > 0 {
216216
// The error may have empty message. In this case we treat it as a transparent error.
217217
// Thus `ident == 0` can be possible.
218-
msg += strings.Repeat(" ", ident) + "caused by: "
218+
msg.WriteString(strings.Repeat(" ", ident) + "caused by: ")
219219
}
220-
msg += fmt.Sprintf("%s\n", cause.Error())
220+
msg.WriteString(fmt.Sprintf("%s\n", cause.Error()))
221221
}
222222
break
223223
}
224224
}
225-
_, _ = tui.ColorErrorMsg.Fprintf(os.Stderr, "\nError: %s", msg)
225+
_, _ = tui.ColorErrorMsg.Fprintf(os.Stderr, "\nError: %s", msg.String())
226226
}
227227

228228
func extractSuggestionFromErrorX(err *errorx.Error) string {

components/dm/command/root.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,20 @@ func printErrorMessageForNormalError(err error) {
178178
}
179179

180180
func printErrorMessageForErrorX(err *errorx.Error) {
181-
msg := ""
181+
var msg strings.Builder
182182
ident := 0
183183
causeErrX := err
184184
for causeErrX != nil {
185185
if ident > 0 {
186-
msg += strings.Repeat(" ", ident) + "caused by: "
186+
msg.WriteString(strings.Repeat(" ", ident) + "caused by: ")
187187
}
188188
currentErrMsg := causeErrX.Message()
189189
if len(currentErrMsg) > 0 {
190190
if ident == 0 {
191191
// Print error code only for top level error
192-
msg += fmt.Sprintf("%s (%s)\n", currentErrMsg, causeErrX.Type().FullName())
192+
msg.WriteString(fmt.Sprintf("%s (%s)\n", currentErrMsg, causeErrX.Type().FullName()))
193193
} else {
194-
msg += fmt.Sprintf("%s\n", currentErrMsg)
194+
msg.WriteString(fmt.Sprintf("%s\n", currentErrMsg))
195195
}
196196
ident++
197197
}
@@ -203,14 +203,14 @@ func printErrorMessageForErrorX(err *errorx.Error) {
203203
if ident > 0 {
204204
// Out most error may have empty message. In this case we treat it as a transparent error.
205205
// Thus `ident == 0` can be possible.
206-
msg += strings.Repeat(" ", ident) + "caused by: "
206+
msg.WriteString(strings.Repeat(" ", ident) + "caused by: ")
207207
}
208-
msg += fmt.Sprintf("%s\n", cause.Error())
208+
msg.WriteString(fmt.Sprintf("%s\n", cause.Error()))
209209
}
210210
break
211211
}
212212
}
213-
_, _ = tui.ColorErrorMsg.Fprintf(os.Stderr, "\nError: %s", msg)
213+
_, _ = tui.ColorErrorMsg.Fprintf(os.Stderr, "\nError: %s", msg.String())
214214
}
215215

216216
func extractSuggestionFromErrorX(err *errorx.Error) string {

components/dm/spec/topology_dm.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ const (
3636
)
3737

3838
var (
39-
globalOptionTypeName = reflect.TypeOf(GlobalOptions{}).Name()
40-
monitorOptionTypeName = reflect.TypeOf(MonitoredOptions{}).Name()
41-
serverConfigsTypeName = reflect.TypeOf(DMServerConfigs{}).Name()
42-
componentSourcesTypeName = reflect.TypeOf(ComponentSources{}).Name()
39+
globalOptionTypeName = reflect.TypeFor[GlobalOptions]().Name()
40+
monitorOptionTypeName = reflect.TypeFor[MonitoredOptions]().Name()
41+
serverConfigsTypeName = reflect.TypeFor[DMServerConfigs]().Name()
42+
componentSourcesTypeName = reflect.TypeFor[ComponentSources]().Name()
4343
)
4444

4545
func setDefaultDir(parent, role, port string, field reflect.Value) {
@@ -63,7 +63,7 @@ func findField(v reflect.Value, fieldName string) (int, bool) {
6363

6464
// Skip global/monitored/job options
6565
func isSkipField(field reflect.Value) bool {
66-
if field.Kind() == reflect.Ptr {
66+
if field.Kind() == reflect.Pointer {
6767
if field.IsZero() {
6868
return true
6969
}
@@ -321,7 +321,7 @@ func (s *Specification) platformConflictsDetect() error {
321321

322322
platformStats := map[string]conflict{}
323323
topoSpec := reflect.ValueOf(s).Elem()
324-
topoType := reflect.TypeOf(s).Elem()
324+
topoType := reflect.TypeFor[Specification]()
325325

326326
for i := 0; i < topoSpec.NumField(); i++ {
327327
if isSkipField(topoSpec.Field(i)) {
@@ -393,7 +393,7 @@ func (s *Specification) portConflictsDetect() error {
393393
portStats := map[usedPort]conflict{}
394394
uniqueHosts := set.NewStringSet()
395395
topoSpec := reflect.ValueOf(s).Elem()
396-
topoType := reflect.TypeOf(s).Elem()
396+
topoType := reflect.TypeFor[Specification]()
397397

398398
for i := 0; i < topoSpec.NumField(); i++ {
399399
if isSkipField(topoSpec.Field(i)) {
@@ -506,7 +506,7 @@ func (s *Specification) dirConflictsDetect() error {
506506
)
507507

508508
topoSpec := reflect.ValueOf(s).Elem()
509-
topoType := reflect.TypeOf(s).Elem()
509+
topoType := reflect.TypeFor[Specification]()
510510

511511
for i := 0; i < topoSpec.NumField(); i++ {
512512
if isSkipField(topoSpec.Field(i)) {
@@ -757,7 +757,7 @@ func setDMCustomDefaults(globalOptions *GlobalOptions, field reflect.Value) erro
757757
return err
758758
}
759759
field.Set(ref.Elem())
760-
case reflect.Ptr:
760+
case reflect.Pointer:
761761
if err := setDMCustomDefaults(globalOptions, field.Elem()); err != nil {
762762
return err
763763
}

components/playground-ng/boot_executor.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ func (e *bootExecutor) Download(ctx context.Context, plan BootPlan) error {
140140
g, gctx := errgroup.WithContext(ctx)
141141
g.SetLimit(maxParallelComponentDownloads)
142142
for _, d := range prepared {
143-
d := d
144143
g.Go(func() error {
145144
return downloadAndInstallComponent(gctx, mirror.Source(), profile, d, downloadInstallOptions{
146145
disableDecompress: disableDecompress,
@@ -155,7 +154,6 @@ func (e *bootExecutor) Download(ctx context.Context, plan BootPlan) error {
155154
g, _ := errgroup.WithContext(ctx)
156155
g.SetLimit(maxParallelComponentDownloads)
157156
for _, d := range downloads {
158-
d := d
159157
g.Go(func() error {
160158
return e.src.EnsureInstalled(d.ComponentID, d.ResolvedVersion)
161159
})

components/playground-ng/boot_executor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func TestBootExecutor_Download_RespectsConcurrencyLimit(t *testing.T) {
308308
executor := newBootExecutor(nil, src)
309309

310310
plan := BootPlan{Downloads: make([]DownloadPlan, 0, total)}
311-
for i := 0; i < total; i++ {
311+
for i := range total {
312312
plan.Downloads = append(plan.Downloads, DownloadPlan{
313313
ComponentID: "comp-" + strconv.Itoa(i),
314314
ResolvedVersion: "v1.0.0",
@@ -320,7 +320,7 @@ func TestBootExecutor_Download_RespectsConcurrencyLimit(t *testing.T) {
320320
errCh <- executor.Download(ctx, plan)
321321
}()
322322

323-
for i := 0; i < maxParallelComponentDownloads; i++ {
323+
for range maxParallelComponentDownloads {
324324
select {
325325
case <-entered:
326326
case <-ctx.Done():

components/playground-ng/catalog_flags.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func applyServiceDefaults(flagSet *pflag.FlagSet, opts *BootOptions) error {
117117
// Apply default counts first (some later defaults depend on these).
118118
{
119119
specs := pgservice.AllSpecs()
120-
for i := 0; i < 8; i++ {
120+
for range 8 {
121121
changed := false
122122
for _, spec := range specs {
123123
def := spec.Catalog
@@ -228,7 +228,6 @@ func registerLegacyScaleOutFlags(cmd *cobra.Command) *legacyScaleOutFlags {
228228

229229
flags := cmd.Flags()
230230
for _, spec := range specs {
231-
spec := spec
232231
if spec.serviceID == "" || spec.flagPrefix == "" {
233232
continue
234233
}

components/playground-ng/command.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ func scaleIn(out io.Writer, reqs []ScaleInRequest, state *cliState) error {
473473

474474
var cmds []Command
475475
for _, req := range reqs {
476-
req := req
477476
if req.Name == "" && req.PID <= 0 {
478477
continue
479478
}
@@ -505,7 +504,6 @@ func scaleOut(out io.Writer, reqs []ScaleOutRequest, state *cliState) (num int,
505504

506505
cmds := make([]Command, 0, len(reqs))
507506
for _, req := range reqs {
508-
req := req
509507
cmds = append(cmds, Command{
510508
Type: ScaleOutCommandType,
511509
ScaleOut: &req,

components/playground-ng/controller_state.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (s *controllerState) removeProcByPID(serviceID proc.ServiceID, pid int) (pr
4444
}
4545

4646
list := s.procs[serviceID]
47-
for i := 0; i < len(list); i++ {
47+
for i := range list {
4848
inst := list[i]
4949
if inst == nil {
5050
continue
@@ -66,7 +66,7 @@ func (s *controllerState) removeProc(serviceID proc.ServiceID, inst proc.Process
6666
}
6767

6868
list := s.procs[serviceID]
69-
for i := 0; i < len(list); i++ {
69+
for i := range list {
7070
if list[i] != inst {
7171
continue
7272
}

components/playground-ng/daemon_files.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ func readPIDFile(path string) (pidFile, error) {
5252
var out pidFile
5353
seenPID := false
5454

55-
lines := strings.Split(string(data), "\n")
56-
for _, line := range lines {
55+
lines := strings.SplitSeq(string(data), "\n")
56+
for line := range lines {
5757
line = strings.TrimSpace(line)
5858
if line == "" {
5959
continue

components/playground-ng/daemon_files_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestReadPIDFile_ParsesStartedAtAndTag(t *testing.T) {
2222
pidPath := filepath.Join(base, playgroundPIDFileName)
2323

2424
startedAt := "2026-01-13T20:00:00Z"
25-
require.NoError(t, os.WriteFile(pidPath, []byte(fmt.Sprintf("pid=123\nstarted_at=%s\ntag=my-cluster\n", startedAt)), 0o644))
25+
require.NoError(t, os.WriteFile(pidPath, fmt.Appendf(nil, "pid=123\nstarted_at=%s\ntag=my-cluster\n", startedAt), 0o644))
2626

2727
got, err := readPIDFile(pidPath)
2828
require.NoError(t, err)
@@ -85,7 +85,7 @@ func TestCleanupStaleRuntimeFiles_RemovesStalePIDAndPort(t *testing.T) {
8585

8686
stalePID := 999999
8787
found := false
88-
for i := 0; i < 1000; i++ {
88+
for i := range 1000 {
8989
pid := stalePID + i
9090
running, err := isPIDRunning(pid)
9191
if err == nil && !running {

0 commit comments

Comments
 (0)