Skip to content

Commit fe0bd17

Browse files
committed
Apply fixes suggested by modernize
The "modernize" analyzer of "gopls" also has a tool to apply fixes en masse. These are the changes produced by: modernize -category=-omitzero -fix -test ./... See: https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize
1 parent 1dfeddd commit fe0bd17

File tree

12 files changed

+27
-34
lines changed

12 files changed

+27
-34
lines changed

internal/collector/config.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
_ "embed"
1010
"fmt"
11+
"maps"
1112
"math"
1213
"strings"
1314
"time"
@@ -168,9 +169,7 @@ func NewConfig(spec *v1beta1.InstrumentationSpec) *Config {
168169

169170
// If there are exporters defined in the spec, add them to the config.
170171
if spec != nil && spec.Config != nil && spec.Config.Exporters != nil {
171-
for k, v := range spec.Config.Exporters {
172-
config.Exporters[k] = v
173-
}
172+
maps.Copy(config.Exporters, spec.Config.Exporters)
174173
}
175174

176175
return config

internal/controller/postgrescluster/controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ spec:
349349
MatchFields(IgnoreExtras, Fields{
350350
"Manager": Equal(string(test.Reconciler.Owner)),
351351
"FieldsV1": PointTo(MatchAllFields(Fields{
352-
"Raw": WithTransform(func(in []byte) (out map[string]interface{}) {
352+
"Raw": WithTransform(func(in []byte) (out map[string]any) {
353353
Expect(yaml.Unmarshal(in, &out)).To(Succeed())
354354
return out
355355
}, MatchAllKeys(Keys{
@@ -367,7 +367,7 @@ spec:
367367
MatchFields(IgnoreExtras, Fields{
368368
"Manager": Equal(string(test.Reconciler.Owner)),
369369
"FieldsV1": PointTo(MatchAllFields(Fields{
370-
"Raw": WithTransform(func(in []byte) (out map[string]interface{}) {
370+
"Raw": WithTransform(func(in []byte) (out map[string]any) {
371371
Expect(yaml.Unmarshal(in, &out)).To(Succeed())
372372
return out
373373
}, MatchAllKeys(Keys{
@@ -380,7 +380,7 @@ spec:
380380
MatchFields(IgnoreExtras, Fields{
381381
"Manager": Equal(string(test.Reconciler.Owner)),
382382
"FieldsV1": PointTo(MatchAllFields(Fields{
383-
"Raw": WithTransform(func(in []byte) (out map[string]interface{}) {
383+
"Raw": WithTransform(func(in []byte) (out map[string]any) {
384384
Expect(yaml.Unmarshal(in, &out)).To(Succeed())
385385
return out
386386
}, MatchAllKeys(Keys{

internal/controller/postgrescluster/instance.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"io"
11+
"maps"
1112
"sort"
1213
"strings"
1314
"time"
@@ -321,9 +322,7 @@ func (r *Reconciler) observeInstances(
321322
if autogrow {
322323
for _, statusIS := range cluster.Status.InstanceSets {
323324
if statusIS.DesiredPGDataVolume != nil {
324-
for k, v := range statusIS.DesiredPGDataVolume {
325-
previousDesiredRequests[k] = v
326-
}
325+
maps.Copy(previousDesiredRequests, statusIS.DesiredPGDataVolume)
327326
}
328327
}
329328
}

internal/controller/standalone_pgadmin/configmap.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
"encoding/json"
1111
"fmt"
12+
"maps"
1213
"slices"
1314
"sort"
1415
"strconv"
@@ -124,9 +125,7 @@ func generateConfig(pgadmin *v1beta1.PGAdmin,
124125
}
125126

126127
// Copy any specified settings over the defaults.
127-
for k, v := range pgadmin.Spec.Config.Settings {
128-
settings[k] = v
129-
}
128+
maps.Copy(settings, pgadmin.Spec.Config.Settings)
130129

131130
// Write mandatory settings over any specified ones.
132131
// SERVER_MODE must always be enabled when running on a webserver.
@@ -246,9 +245,7 @@ func generateGunicornConfig(pgadmin *v1beta1.PGAdmin,
246245
}
247246

248247
// Copy any specified settings over the defaults.
249-
for k, v := range pgadmin.Spec.Config.Gunicorn {
250-
settings[k] = v
251-
}
248+
maps.Copy(settings, pgadmin.Spec.Config.Gunicorn)
252249

253250
// Write mandatory settings over any specified ones.
254251
// - https://docs.gunicorn.org/en/latest/settings.html#workers

internal/kubeapi/patch_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313
"k8s.io/apimachinery/pkg/types"
1414
)
1515

16-
func assertJSON(t testing.TB, expected interface{}, actual []byte) {
16+
func assertJSON(t testing.TB, expected any, actual []byte) {
1717
t.Helper()
1818

19-
var e, a interface{}
19+
var e, a any
2020
var err error
2121

2222
if b, ok := expected.([]byte); ok {
@@ -248,7 +248,7 @@ func TestMerge7386Equivalence(t *testing.T) {
248248

249249
// one call using other types
250250
NewMergePatch().
251-
Add("metadata")(map[string]interface{}{
251+
Add("metadata")(map[string]any{
252252
"labels": labels.Set{"lk": "lv"},
253253
"annotations": map[string]string{"ak1": "av1", "ak2": "av2"},
254254
}),

internal/logging/logrus.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func Logrus(out io.Writer, version string, debug, verbosity int) logr.LogSink {
3838
return &sink{
3939
verbosity: verbosity,
4040

41-
fnError: func(err error, message string, kv ...interface{}) {
41+
fnError: func(err error, message string, kv ...any) {
4242
entry := root.WithField("version", version)
4343
entry = logrusFields(entry, kv...)
4444

@@ -57,7 +57,7 @@ func Logrus(out io.Writer, version string, debug, verbosity int) logr.LogSink {
5757
entry.Log(logrus.ErrorLevel, message)
5858
},
5959

60-
fnInfo: func(level int, message string, kv ...interface{}) {
60+
fnInfo: func(level int, message string, kv ...any) {
6161
entry := root.WithField("version", version)
6262
entry = logrusFields(entry, kv...)
6363

@@ -72,15 +72,15 @@ func Logrus(out io.Writer, version string, debug, verbosity int) logr.LogSink {
7272

7373
// logrusFields structures and adds the key/value interface to the logrus.Entry;
7474
// for instance, if a key is not a string, this formats the key as a string.
75-
func logrusFields(entry *logrus.Entry, kv ...interface{}) *logrus.Entry {
75+
func logrusFields(entry *logrus.Entry, kv ...any) *logrus.Entry {
7676
if len(kv) == 0 {
7777
return entry
7878
}
7979
if len(kv)%2 == 1 {
8080
kv = append(kv, nil)
8181
}
8282

83-
m := make(map[string]interface{}, len(kv)/2)
83+
m := make(map[string]any, len(kv)/2)
8484

8585
for i := 0; i < len(kv); i += 2 {
8686
key, ok := kv[i].(string)

internal/patroni/config.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package patroni
66

77
import (
88
"fmt"
9+
"maps"
910
"path"
1011
"strings"
1112

@@ -237,9 +238,7 @@ func DynamicConfiguration(
237238

238239
// Copy the "postgresql" section over the above defaults.
239240
if section, ok := root["postgresql"].(map[string]any); ok {
240-
for k, v := range section {
241-
postgresql[k] = v
242-
}
241+
maps.Copy(postgresql, section)
243242
}
244243
if m := parameters.AsMap(); m != nil {
245244
postgresql["parameters"] = m

internal/pgadmin/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ if os.path.isfile('` + ldapPasswordAbsolutePath + `'):
153153
}
154154

155155
// systemSettings returns pgAdmin settings as a value that can be marshaled to JSON.
156-
func systemSettings(spec *v1beta1.PGAdminPodSpec) map[string]interface{} {
156+
func systemSettings(spec *v1beta1.PGAdminPodSpec) map[string]any {
157157
settings := spec.Config.Settings.DeepCopy()
158158
if settings == nil {
159-
settings = make(map[string]interface{})
159+
settings = make(map[string]any)
160160
}
161161

162162
// SERVER_MODE must always be enabled when running on a webserver.

internal/pgadmin/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ func TestSystemSettings(t *testing.T) {
106106
SERVER_MODE: true
107107
`))
108108

109-
spec.Config.Settings = map[string]interface{}{
110-
"ALLOWED_HOSTS": []interface{}{"225.0.0.0/8", "226.0.0.0/7", "228.0.0.0/6"},
109+
spec.Config.Settings = map[string]any{
110+
"ALLOWED_HOSTS": []any{"225.0.0.0/8", "226.0.0.0/7", "228.0.0.0/6"},
111111
}
112112
assert.Assert(t, cmp.MarshalMatches(systemSettings(spec), `
113113
ALLOWED_HOSTS:

internal/pgadmin/reconcile_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pgadmin-settings.json: |
4747
t.Run("Customizations", func(t *testing.T) {
4848
cluster.Spec.UserInterface = new(v1beta1.UserInterfaceSpec)
4949
cluster.Spec.UserInterface.PGAdmin = new(v1beta1.PGAdminPodSpec)
50-
cluster.Spec.UserInterface.PGAdmin.Config.Settings = map[string]interface{}{
50+
cluster.Spec.UserInterface.PGAdmin.Config.Settings = map[string]any{
5151
"some": "thing",
5252
"UPPER_CASE": false,
5353
}

0 commit comments

Comments
 (0)