Skip to content

Commit e88ef34

Browse files
committed
go fix: modernize code (interface{} -> any, SplitSeq, fmt.Appendf, drop build constraints)
1 parent b71fd51 commit e88ef34

13 files changed

Lines changed: 24 additions & 30 deletions

File tree

cmd/flexctl/backups.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ type successfulUpdateResult struct {
308308
}
309309

310310
type configUpdateResult struct {
311-
Result successfulUpdateResult `json:"result,omitempty"`
311+
Result successfulUpdateResult `json:"result"`
312312
Error string `json:"error,omitempty"`
313313
}
314314

internal/api/handle_admin.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package api
33
import (
44
"encoding/json"
55
"fmt"
6+
"maps"
67
"net/http"
78
"os"
89
"strings"
@@ -145,7 +146,7 @@ func handleUpdatePostgresSettings(w http.ResponseWriter, r *http.Request) {
145146
return
146147
}
147148

148-
var requestedChanges map[string]interface{}
149+
var requestedChanges map[string]any
149150
if err := json.NewDecoder(r.Body).Decode(&requestedChanges); err != nil {
150151
renderErr(w, err)
151152
return
@@ -158,9 +159,7 @@ func handleUpdatePostgresSettings(w http.ResponseWriter, r *http.Request) {
158159
return
159160
}
160161

161-
for k, v := range requestedChanges {
162-
cfg[k] = v
163-
}
162+
maps.Copy(cfg, requestedChanges)
164163

165164
node.PGConfig.SetUserConfig(cfg)
166165

@@ -287,7 +286,7 @@ func handleViewRepmgrSettings(w http.ResponseWriter, r *http.Request) {
287286
return
288287
}
289288

290-
out := map[string]interface{}{}
289+
out := map[string]any{}
291290

292291
for key := range all {
293292
val := all[key]
@@ -362,7 +361,7 @@ func handleUpdateBarmanSettings(w http.ResponseWriter, r *http.Request) {
362361
return
363362
}
364363

365-
var requestedChanges map[string]interface{}
364+
var requestedChanges map[string]any
366365
if err := json.NewDecoder(r.Body).Decode(&requestedChanges); err != nil {
367366
renderErr(w, err)
368367
return
@@ -373,9 +372,7 @@ func handleUpdateBarmanSettings(w http.ResponseWriter, r *http.Request) {
373372
return
374373
}
375374

376-
for k, v := range requestedChanges {
377-
cfg[k] = v
378-
}
375+
maps.Copy(cfg, requestedChanges)
379376

380377
barman.SetUserConfig(cfg)
381378

internal/api/response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/jackc/pgx/v5"
1111
)
1212

13-
func renderJSON(w http.ResponseWriter, data interface{}, status int) {
13+
func renderJSON(w http.ResponseWriter, data any, status int) {
1414
w.Header().Set("Content-Type", "application/json")
1515
w.WriteHeader(status)
1616
if err := json.NewEncoder(w).Encode(data); err != nil {

internal/api/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ type errRes struct {
1616
}
1717

1818
type Response struct {
19-
Result interface{} `json:"result,omitempty"`
20-
Error string `json:"error,omitempty"`
19+
Result any `json:"result,omitempty"`
20+
Error string `json:"error,omitempty"`
2121
}

internal/flycheck/barman.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ func CheckBarmanConnection(checks *check.CheckSuite) *check.CheckSuite {
2525
// Each line besides the first represents a check and will include FAILED or OK
2626
// We just separate those lines and create a health check entry of our own
2727
// so it's uniform how we handle it
28-
lines := strings.Split(string(output), "\n")
28+
lines := strings.SplitSeq(string(output), "\n")
2929

30-
for _, line := range lines {
30+
for line := range lines {
3131
pattern := `\s*(.*?):(.*)$`
3232
regex := regexp.MustCompile(pattern)
3333
matches := regex.FindStringSubmatch(line)

internal/flypg/admin/admin.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func DropOwned(ctx context.Context, conn *pgx.Conn, user string) error {
330330
return nil
331331
}
332332

333-
func SetConfigurationSetting(ctx context.Context, conn *pgx.Conn, key string, value interface{}) error {
333+
func SetConfigurationSetting(ctx context.Context, conn *pgx.Conn, key string, value any) error {
334334
sql := fmt.Sprintf("SET %s to %s", key, value)
335335
_, err := conn.Exec(ctx, sql)
336336
return err
@@ -400,7 +400,7 @@ func GetSetting(ctx context.Context, pg *pgx.Conn, setting string) (*PGSetting,
400400
return &out, nil
401401
}
402402

403-
func ValidatePGSettings(ctx context.Context, conn *pgx.Conn, requested map[string]interface{}) error {
403+
func ValidatePGSettings(ctx context.Context, conn *pgx.Conn, requested map[string]any) error {
404404
for k, v := range requested {
405405
exists, err := SettingExists(ctx, conn, k)
406406
if err != nil {
@@ -413,8 +413,8 @@ func ValidatePGSettings(ctx context.Context, conn *pgx.Conn, requested map[strin
413413
// Verify specified extensions are installed
414414
if k == "shared_preload_libraries" {
415415
extensions := strings.Trim(v.(string), "'")
416-
extSlice := strings.Split(extensions, ",")
417-
for _, e := range extSlice {
416+
extSlice := strings.SplitSeq(extensions, ",")
417+
for e := range extSlice {
418418
available, err := ExtensionAvailable(ctx, conn, e)
419419
if err != nil {
420420
return fmt.Errorf("failed to verify pg extension %s: %s", e, err)

internal/privnet/sixpn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func AllMachines(ctx context.Context, appName string) ([]Machine, error) {
5656

5757
machines := make([]Machine, 0)
5858
for _, txt := range txts {
59-
parts := strings.Split(txt, ",")
60-
for _, part := range parts {
59+
parts := strings.SplitSeq(txt, ",")
60+
for part := range parts {
6161
parts := strings.Split(part, " ")
6262
if len(parts) != 2 {
6363
return nil, fmt.Errorf("invalid machine DNS TXT format: %s", txt)

internal/supervisor/ensure_kill.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !linux
2-
// +build !linux
32

43
// Package supervisor manages the lifecycle of supervised processes.
54
package supervisor

internal/supervisor/ensure_kill_linux.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build linux
2-
// +build linux
32

43
package supervisor
54

internal/supervisor/output.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ func (m *multiOutput) ClosePipe(proc *process) {
109109
}
110110

111111
func (m *multiOutput) WriteErr(proc *process, err error) {
112-
m.WriteLine(proc, []byte(
113-
fmt.Sprintf("\033[0;31m%v\033[0m", err),
114-
))
112+
m.WriteLine(proc,
113+
fmt.Appendf(nil, "\033[0;31m%v\033[0m", err))
115114
}

0 commit comments

Comments
 (0)