Skip to content

Commit d2de93e

Browse files
committed
modernize
1 parent a8795d6 commit d2de93e

File tree

130 files changed

+438
-472
lines changed

Some content is hidden

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

130 files changed

+438
-472
lines changed

pkg/assets/link.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ var linkFmtThreshold = (*Link)(new(big.Int).Exp(big.NewInt(10), big.NewInt(12),
9898
// MarshalText implements the encoding.TextMarshaler interface.
9999
func (l *Link) MarshalText() ([]byte, error) {
100100
if l.Cmp(linkFmtThreshold) >= 0 {
101-
return []byte(fmt.Sprintf("%s link", decimal.NewFromBigInt(l.ToInt(), -18))), nil
101+
return fmt.Appendf(nil, "%s link", decimal.NewFromBigInt(l.ToInt(), -18)), nil
102102
}
103103
return (*big.Int)(l).MarshalText()
104104
}
@@ -109,7 +109,7 @@ func (l Link) MarshalJSON() ([]byte, error) {
109109
if err != nil {
110110
return nil, err
111111
}
112-
return []byte(fmt.Sprintf(`"%s"`, value)), nil
112+
return fmt.Appendf(nil, `"%s"`, value), nil
113113
}
114114

115115
// UnmarshalJSON implements the json.Unmarshaler interface.
@@ -166,7 +166,7 @@ func (l Link) Value() (driver.Value, error) {
166166
}
167167

168168
// Scan reads the database value and returns an instance.
169-
func (l *Link) Scan(value interface{}) error {
169+
func (l *Link) Scan(value any) error {
170170
switch v := value.(type) {
171171
case string:
172172
decoded, ok := l.SetString(v, 10)

pkg/beholder/chip_ingress_emitter.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package beholder
33
import (
44
"context"
55
"fmt"
6+
"maps"
67

78
"github.com/smartcontractkit/chainlink-common/pkg/chipingress"
89
)
@@ -83,9 +84,7 @@ func ExtractAttributes(attrKVs ...any) map[string]any {
8384
attributes := newAttributes(attrKVs...)
8485

8586
attributesMap := make(map[string]any)
86-
for key, value := range attributes {
87-
attributesMap[key] = value
88-
}
87+
maps.Copy(attributesMap, attributes)
8988

9089
return attributesMap
9190
}

pkg/beholder/message.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package beholder
33
import (
44
"errors"
55
"fmt"
6+
"maps"
67
"regexp"
78
"strings"
89

@@ -80,9 +81,7 @@ func newAttributes(attrKVs ...any) Attributes {
8081
for i := 0; i < l; {
8182
switch t := attrKVs[i].(type) {
8283
case Attributes:
83-
for k, v := range t {
84-
a[k] = v
85-
}
84+
maps.Copy(a, t)
8685
i++
8786
case string:
8887
if i+1 >= l {
@@ -111,9 +110,7 @@ func (e *Message) AddAttributes(attrKVs ...any) {
111110
if e.Attrs == nil {
112111
e.Attrs = make(map[string]any, len(attrs)/2)
113112
}
114-
for k, v := range attrs {
115-
e.Attrs[k] = v
116-
}
113+
maps.Copy(e.Attrs, attrs)
117114
}
118115

119116
func (e *Message) OtelRecord() otellog.Record {
@@ -122,9 +119,7 @@ func (e *Message) OtelRecord() otellog.Record {
122119

123120
func (e *Message) Copy() Message {
124121
attrs := make(Attributes, len(e.Attrs))
125-
for k, v := range e.Attrs {
126-
attrs[k] = v
127-
}
122+
maps.Copy(attrs, e.Attrs)
128123
c := Message{
129124
Attrs: attrs,
130125
}

pkg/capabilities/capabilities_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func TestOCRTriggerEvent_ToMapFromMap(t *testing.T) {
250250
// Test error handling
251251

252252
t.Run("invalid map missing key", func(t *testing.T) {
253-
invalidMap, err := values.NewMap(map[string]interface{}{
253+
invalidMap, err := values.NewMap(map[string]any{
254254
"WrongKey": "value",
255255
})
256256
require.NoError(t, err)

pkg/capabilities/cli/cmd/generate-user-types/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func genForStruct() func(string) bool {
7676

7777
func buildSkipGen() map[string]bool {
7878
skipGen := map[string]bool{}
79-
for _, skip := range strings.Split(*skipCap, ",") {
79+
for skip := range strings.SplitSeq(*skipCap, ",") {
8080
skipGen[skip] = true
8181
}
8282
return skipGen
@@ -86,7 +86,7 @@ func buildGenPkgType() func(string) bool {
8686
genPkgType := func(_ string) bool { return true }
8787
if *types != "" {
8888
genPkg := map[string]bool{}
89-
for _, t := range strings.Split(*types, ",") {
89+
for t := range strings.SplitSeq(*types, ",") {
9090
genPkg[t] = true
9191
}
9292
genPkgType = func(s string) bool {

pkg/capabilities/cli/cmd/generate_user_types.go

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

33
import (
44
"errors"
5+
"maps"
56
"os"
67
"path"
78
"strings"
@@ -43,9 +44,7 @@ func GenerateUserTypes(info UserGenerationInfo) error {
4344
if i == 0 {
4445
generatedInfo = fileGeneratedInfo
4546
} else {
46-
for name, strct := range fileGeneratedInfo.Types {
47-
generatedInfo.Types[name] = strct
48-
}
47+
maps.Copy(generatedInfo.Types, fileGeneratedInfo.Types)
4948
}
5049
}
5150

pkg/capabilities/consensus/ocr3/aggregators/reduce_aggregator.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"math"
99
"math/big"
10+
"slices"
1011
"sort"
1112
"strconv"
1213
"time"
@@ -229,7 +230,7 @@ func (a *reduceAggregator) shouldReport(lggr logger.Logger, field AggregationFie
229230
if !bytes.Equal(v, unwrappedSingleValue.([]byte)) {
230231
return true, nil
231232
}
232-
case map[string]interface{}, []any:
233+
case map[string]any, []any:
233234
marshalledOldValue, err := proto.MarshalOptions{Deterministic: true}.Marshal(values.Proto(oldValue))
234235
if err != nil {
235236
return false, err
@@ -545,12 +546,7 @@ func formatReport(report map[string]any, format string) (any, error) {
545546
}
546547

547548
func isOneOf(toCheck string, options []string) bool {
548-
for _, option := range options {
549-
if toCheck == option {
550-
return true
551-
}
552-
}
553-
return false
549+
return slices.Contains(options, toCheck)
554550
}
555551

556552
func NewReduceAggregator(config values.Map) (types.Aggregator, error) {

0 commit comments

Comments
 (0)