Skip to content

Commit 7e8003c

Browse files
authored
Merge pull request #964 from sunnyraindy/master
refactor: replace interface{} with any for clarity and modernization
2 parents b9877fa + a88ddb5 commit 7e8003c

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

addons/graffiti_wall_writer/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func NewConfig() *GraffitiWallWriterConfig {
4040
Name: "Enabled",
4141
Description: "Enable the Graffiti Wall Writer",
4242
Type: config.ParameterType_Bool,
43-
Default: map[config.Network]interface{}{config.Network_All: false},
43+
Default: map[config.Network]any{config.Network_All: false},
4444
AffectsContainers: []config.ContainerID{ContainerID_GraffitiWallWriter, config.ContainerID_Validator},
4545
CanBeBlank: false,
4646
OverwriteOnUpgrade: false,
@@ -51,7 +51,7 @@ func NewConfig() *GraffitiWallWriterConfig {
5151
Name: "Input URL",
5252
Description: "URL or filepath for the input JSON file that contains the graffiti image to write to the wall. By default, this is the Rocket Pool logo.\n\nSee https://gist.github.com/RomiRand/dfa1b5286af3e926deff0be2746db2df for info on making your own images.\n\nNOTE: for local files, you must manually put the file into the `addons/gww` folder of your `rocketpool` directory, and then enter the name of it as `/gww/<filename>` here.",
5353
Type: config.ParameterType_String,
54-
Default: map[config.Network]interface{}{config.Network_All: "https://cdn-rocketpool.s3.us-west-2.amazonaws.com/graffiti.json"},
54+
Default: map[config.Network]any{config.Network_All: "https://cdn-rocketpool.s3.us-west-2.amazonaws.com/graffiti.json"},
5555
AffectsContainers: []config.ContainerID{ContainerID_GraffitiWallWriter},
5656
CanBeBlank: true,
5757
OverwriteOnUpgrade: false,
@@ -62,7 +62,7 @@ func NewConfig() *GraffitiWallWriterConfig {
6262
Name: "Wall Update Interval",
6363
Description: "The time, in seconds, between updating the beaconcha.in graffiti wall canvas",
6464
Type: config.ParameterType_Uint,
65-
Default: map[config.Network]interface{}{config.Network_All: uint64(600)},
65+
Default: map[config.Network]any{config.Network_All: uint64(600)},
6666
AffectsContainers: []config.ContainerID{ContainerID_GraffitiWallWriter},
6767
CanBeBlank: true,
6868
OverwriteOnUpgrade: false,
@@ -73,7 +73,7 @@ func NewConfig() *GraffitiWallWriterConfig {
7373
Name: "Input Update Interval",
7474
Description: "The time, in seconds, between input updates - only if remote URL is used. File will be instantly reloaded when changed.",
7575
Type: config.ParameterType_Uint,
76-
Default: map[config.Network]interface{}{config.Network_All: uint64(600)},
76+
Default: map[config.Network]any{config.Network_All: uint64(600)},
7777
AffectsContainers: []config.ContainerID{ContainerID_GraffitiWallWriter},
7878
CanBeBlank: true,
7979
OverwriteOnUpgrade: false,
@@ -84,7 +84,7 @@ func NewConfig() *GraffitiWallWriterConfig {
8484
Name: "Pixel Update Interval",
8585
Description: "The time, in seconds, between output updates.",
8686
Type: config.ParameterType_Uint,
87-
Default: map[config.Network]interface{}{config.Network_All: uint64(60)},
87+
Default: map[config.Network]any{config.Network_All: uint64(60)},
8888
AffectsContainers: []config.ContainerID{ContainerID_GraffitiWallWriter},
8989
CanBeBlank: true,
9090
OverwriteOnUpgrade: false,
@@ -95,7 +95,7 @@ func NewConfig() *GraffitiWallWriterConfig {
9595
Name: "Container Tag",
9696
Description: "The tag name of the container you want to use on Docker Hub.",
9797
Type: config.ParameterType_String,
98-
Default: map[config.Network]interface{}{config.Network_All: containerTag},
98+
Default: map[config.Network]any{config.Network_All: containerTag},
9999
AffectsContainers: []config.ContainerID{ContainerID_GraffitiWallWriter},
100100
CanBeBlank: false,
101101
OverwriteOnUpgrade: true,
@@ -106,7 +106,7 @@ func NewConfig() *GraffitiWallWriterConfig {
106106
Name: "Additional Flags",
107107
Description: "Additional custom command line flags you want to pass to the addon, to take advantage of other settings that the Smartnode's configuration doesn't cover.",
108108
Type: config.ParameterType_String,
109-
Default: map[config.Network]interface{}{config.Network_All: ""},
109+
Default: map[config.Network]any{config.Network_All: ""},
110110
AffectsContainers: []config.ContainerID{ContainerID_GraffitiWallWriter},
111111
CanBeBlank: true,
112112
OverwriteOnUpgrade: false,

bindings/utils/json/json.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55
"fmt"
66
)
77

8-
func Marshal(v interface{}) ([]byte, error) {
8+
func Marshal(v any) ([]byte, error) {
99
return json.Marshal(v)
1010
}
1111

12-
func Unmarshal(data []byte, v interface{}) error {
12+
func Unmarshal(data []byte, v any) error {
1313
err := json.Unmarshal(data, v)
1414
if err != nil {
1515
return fmt.Errorf("%w\nUnable to Unmarshal JSON string %s", err, string(data))

shared/types/config/parameter.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ import (
99

1010
// A parameter that can be configured by the user
1111
type Parameter struct {
12-
ID string `yaml:"id,omitempty"`
13-
Name string `yaml:"name,omitempty"`
14-
Description string `yaml:"description,omitempty"`
15-
Type ParameterType `yaml:"type,omitempty"`
16-
Default map[Network]interface{} `yaml:"default,omitempty"`
17-
MaxLength int `yaml:"maxLength,omitempty"`
18-
Regex string `yaml:"regex,omitempty"`
19-
Advanced bool `yaml:"advanced,omitempty"`
20-
AffectsContainers []ContainerID `yaml:"affectsContainers,omitempty"`
21-
CanBeBlank bool `yaml:"canBeBlank,omitempty"`
22-
OverwriteOnUpgrade bool `yaml:"overwriteOnUpgrade,omitempty"`
23-
Options []ParameterOption `yaml:"options,omitempty"`
24-
Value interface{} `yaml:"-"`
25-
DescriptionsByNetwork map[Network]string `yaml:"-"`
12+
ID string `yaml:"id,omitempty"`
13+
Name string `yaml:"name,omitempty"`
14+
Description string `yaml:"description,omitempty"`
15+
Type ParameterType `yaml:"type,omitempty"`
16+
Default map[Network]any `yaml:"default,omitempty"`
17+
MaxLength int `yaml:"maxLength,omitempty"`
18+
Regex string `yaml:"regex,omitempty"`
19+
Advanced bool `yaml:"advanced,omitempty"`
20+
AffectsContainers []ContainerID `yaml:"affectsContainers,omitempty"`
21+
CanBeBlank bool `yaml:"canBeBlank,omitempty"`
22+
OverwriteOnUpgrade bool `yaml:"overwriteOnUpgrade,omitempty"`
23+
Options []ParameterOption `yaml:"options,omitempty"`
24+
Value any `yaml:"-"`
25+
DescriptionsByNetwork map[Network]string `yaml:"-"`
2626
}
2727

2828
// A single option in a choice parameter
2929
type ParameterOption struct {
30-
Name string `yaml:"name,omitempty"`
31-
Description string `yaml:"description,omitempty"`
32-
Value interface{} `yaml:"value,omitempty"`
30+
Name string `yaml:"name,omitempty"`
31+
Description string `yaml:"description,omitempty"`
32+
Value any `yaml:"value,omitempty"`
3333
}
3434

3535
// Apply a network change to a parameter
@@ -141,7 +141,7 @@ func (param *Parameter) SetToDefault(network Network) error {
141141
}
142142

143143
// Get the default value for the provided network
144-
func (param *Parameter) GetDefault(network Network) (interface{}, error) {
144+
func (param *Parameter) GetDefault(network Network) (any, error) {
145145
defaultSetting, exists := param.Default[network]
146146
if !exists {
147147
defaultSetting, exists = param.Default[Network_All]

shared/utils/log/logger.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
// Logger with ANSI color output
1010
type ColorLogger struct {
1111
Color color.Attribute
12-
sprintFunc func(a ...interface{}) string
13-
sprintfFunc func(format string, a ...interface{}) string
12+
sprintFunc func(a ...any) string
13+
sprintfFunc func(format string, a ...any) string
1414
}
1515

1616
// Create new color logger
@@ -23,21 +23,21 @@ func NewColorLogger(colorAttr color.Attribute) ColorLogger {
2323
}
2424

2525
// Print values
26-
func (l *ColorLogger) Print(v ...interface{}) {
26+
func (l *ColorLogger) Print(v ...any) {
2727
log.Print(l.sprintFunc(v...))
2828
}
2929

3030
// Print values with a newline
31-
func (l *ColorLogger) Println(v ...interface{}) {
31+
func (l *ColorLogger) Println(v ...any) {
3232
log.Println(l.sprintFunc(v...))
3333
}
3434

3535
// Print a formatted string
36-
func (l *ColorLogger) Printf(format string, v ...interface{}) {
36+
func (l *ColorLogger) Printf(format string, v ...any) {
3737
log.Print(l.sprintfFunc(format, v...))
3838
}
3939

4040
// Print a formatted string with a newline
41-
func (l *ColorLogger) Printlnf(format string, v ...interface{}) {
41+
func (l *ColorLogger) Printlnf(format string, v ...any) {
4242
log.Println(l.sprintfFunc(format, v...))
4343
}

0 commit comments

Comments
 (0)