Skip to content

Commit 11b01e2

Browse files
committed
refactor: replace interface{} with any for clarity and modern syntax
1 parent 9a133c7 commit 11b01e2

32 files changed

+108
-108
lines changed

bool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ type BoolValue struct {
99
Bound *bool
1010
}
1111

12-
func (b *BoolValue) GetBound() interface{} {
12+
func (b *BoolValue) GetBound() any {
1313
if b.Bound == nil {
1414
return nil
1515
}
1616
return *b.Bound
1717
}
1818

19-
func (b *BoolValue) Parse(value string) (interface{}, error) {
19+
func (b *BoolValue) Parse(value string) (any, error) {
2020
return strconv.ParseBool(value)
2121
}
2222

23-
func (b *BoolValue) Set(value interface{}) error {
23+
func (b *BoolValue) Set(value any) error {
2424
if val, ok := value.(bool); ok {
2525
*b.Bound = val
2626
return nil

bool_slice.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ type BoolSlicesValue struct {
1010
Bound *[]bool
1111
}
1212

13-
func (b *BoolSlicesValue) GetBound() interface{} {
13+
func (b *BoolSlicesValue) GetBound() any {
1414
if b.Bound == nil {
1515
return nil
1616
}
1717
return *b.Bound
1818
}
1919

20-
func (b *BoolSlicesValue) Parse(value string) (interface{}, error) {
20+
func (b *BoolSlicesValue) Parse(value string) (any, error) {
2121
parsed, err := strconv.ParseBool(value)
2222
if err != nil {
2323
return nil, fmt.Errorf("invalid boolean value: %s, error: %w", value, err)
2424
}
2525
return parsed, nil
2626
}
2727

28-
func (b *BoolSlicesValue) Set(value interface{}) error {
28+
func (b *BoolSlicesValue) Set(value any) error {
2929
if parsedBool, ok := value.(bool); ok {
3030
*b.Bound = append(*b.Bound, parsedBool)
3131
return nil

bool_slice_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestGetBoolSlices(t *testing.T) {
7575

7676
parsedGroup := &dynflags.ParsedGroup{
7777
Name: "testGroup",
78-
Values: map[string]interface{}{
78+
Values: map[string]any{
7979
"flag1": []bool{true, false, true},
8080
},
8181
}
@@ -90,7 +90,7 @@ func TestGetBoolSlices(t *testing.T) {
9090

9191
parsedGroup := &dynflags.ParsedGroup{
9292
Name: "testGroup",
93-
Values: map[string]interface{}{
93+
Values: map[string]any{
9494
"flag1": true,
9595
},
9696
}
@@ -105,7 +105,7 @@ func TestGetBoolSlices(t *testing.T) {
105105

106106
parsedGroup := &dynflags.ParsedGroup{
107107
Name: "testGroup",
108-
Values: map[string]interface{}{},
108+
Values: map[string]any{},
109109
}
110110

111111
result, err := parsedGroup.GetBoolSlices("nonExistentFlag")
@@ -119,7 +119,7 @@ func TestGetBoolSlices(t *testing.T) {
119119

120120
parsedGroup := &dynflags.ParsedGroup{
121121
Name: "testGroup",
122-
Values: map[string]interface{}{
122+
Values: map[string]any{
123123
"flag1": "invalid",
124124
},
125125
}

bool_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestParsedGroup_GetBool(t *testing.T) {
9797

9898
parsedGroup := &dynflags.ParsedGroup{
9999
Name: "testGroup",
100-
Values: map[string]interface{}{"testBool": true},
100+
Values: map[string]any{"testBool": true},
101101
}
102102
value, err := parsedGroup.GetBool("testBool")
103103
assert.NoError(t, err)
@@ -109,7 +109,7 @@ func TestParsedGroup_GetBool(t *testing.T) {
109109

110110
parsedGroup := &dynflags.ParsedGroup{
111111
Name: "testGroup",
112-
Values: map[string]interface{}{},
112+
Values: map[string]any{},
113113
}
114114
value, err := parsedGroup.GetBool("nonExistent")
115115
assert.Error(t, err)
@@ -122,7 +122,7 @@ func TestParsedGroup_GetBool(t *testing.T) {
122122

123123
parsedGroup := &dynflags.ParsedGroup{
124124
Name: "testGroup",
125-
Values: map[string]interface{}{"invalidBool": "notABool"},
125+
Values: map[string]any{"invalidBool": "notABool"},
126126
}
127127
value, err := parsedGroup.GetBool("invalidBool")
128128
assert.Error(t, err)

duration.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ type DurationValue struct {
99
Bound *time.Duration
1010
}
1111

12-
func (d *DurationValue) GetBound() interface{} {
12+
func (d *DurationValue) GetBound() any {
1313
if d.Bound == nil {
1414
return nil
1515
}
1616
return *d.Bound
1717
}
1818

19-
func (d *DurationValue) Parse(value string) (interface{}, error) {
19+
func (d *DurationValue) Parse(value string) (any, error) {
2020
return time.ParseDuration(value)
2121
}
2222

23-
func (d *DurationValue) Set(value interface{}) error {
23+
func (d *DurationValue) Set(value any) error {
2424
if dur, ok := value.(time.Duration); ok {
2525
*d.Bound = dur
2626
return nil

duration_slice.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ type DurationSlicesValue struct {
1010
Bound *[]time.Duration
1111
}
1212

13-
func (d *DurationSlicesValue) GetBound() interface{} {
13+
func (d *DurationSlicesValue) GetBound() any {
1414
if d.Bound == nil {
1515
return nil
1616
}
1717
return *d.Bound
1818
}
1919

20-
func (d *DurationSlicesValue) Parse(value string) (interface{}, error) {
20+
func (d *DurationSlicesValue) Parse(value string) (any, error) {
2121
parsed, err := time.ParseDuration(value)
2222
if err != nil {
2323
return nil, fmt.Errorf("invalid duration value: %s, error: %w", value, err)
2424
}
2525
return parsed, nil
2626
}
2727

28-
func (d *DurationSlicesValue) Set(value interface{}) error {
28+
func (d *DurationSlicesValue) Set(value any) error {
2929
if parsedDuration, ok := value.(time.Duration); ok {
3030
*d.Bound = append(*d.Bound, parsedDuration)
3131
return nil

duration_slice_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestGetDurationSlices(t *testing.T) {
7676

7777
parsedGroup := &dynflags.ParsedGroup{
7878
Name: "testGroup",
79-
Values: map[string]interface{}{
79+
Values: map[string]any{
8080
"flag1": []time.Duration{1 * time.Second, 2 * time.Second, 3 * time.Second},
8181
},
8282
}
@@ -91,7 +91,7 @@ func TestGetDurationSlices(t *testing.T) {
9191

9292
parsedGroup := &dynflags.ParsedGroup{
9393
Name: "testGroup",
94-
Values: map[string]interface{}{
94+
Values: map[string]any{
9595
"flag1": 5 * time.Second,
9696
},
9797
}
@@ -106,7 +106,7 @@ func TestGetDurationSlices(t *testing.T) {
106106

107107
parsedGroup := &dynflags.ParsedGroup{
108108
Name: "testGroup",
109-
Values: map[string]interface{}{},
109+
Values: map[string]any{},
110110
}
111111

112112
result, err := parsedGroup.GetDurationSlices("nonExistentFlag")
@@ -120,7 +120,7 @@ func TestGetDurationSlices(t *testing.T) {
120120

121121
parsedGroup := &dynflags.ParsedGroup{
122122
Name: "testGroup",
123-
Values: map[string]interface{}{
123+
Values: map[string]any{
124124
"flag1": "invalid",
125125
},
126126
}

duration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestParsedGroup_GetDuration(t *testing.T) {
7878

7979
parsed := &dynflags.ParsedGroup{
8080
Name: "test",
81-
Values: map[string]interface{}{"timeout": 30 * time.Second},
81+
Values: map[string]any{"timeout": 30 * time.Second},
8282
}
8383
dur, err := parsed.GetDuration("timeout")
8484
assert.NoError(t, err)
@@ -90,7 +90,7 @@ func TestParsedGroup_GetDuration(t *testing.T) {
9090

9191
parsed := &dynflags.ParsedGroup{
9292
Name: "test",
93-
Values: map[string]interface{}{},
93+
Values: map[string]any{},
9494
}
9595
_, err := parsed.GetDuration("missing")
9696
assert.Error(t, err)
@@ -101,7 +101,7 @@ func TestParsedGroup_GetDuration(t *testing.T) {
101101

102102
parsed := &dynflags.ParsedGroup{
103103
Name: "test",
104-
Values: map[string]interface{}{"timeout": "not a duration"},
104+
Values: map[string]any{"timeout": "not a duration"},
105105
}
106106
_, err := parsed.GetDuration("timeout")
107107
assert.Error(t, err)

flag.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ const (
2121

2222
// Flag represents a single configuration flag
2323
type Flag struct {
24-
Default interface{} // Default value for the flag
25-
Type FlagType // Type of the flag
26-
Usage string // Description for usage
27-
metaVar string // MetaVar for flag
28-
value FlagValue // Encapsulated parsing and value-setting logic
24+
Default any // Default value for the flag
25+
Type FlagType // Type of the flag
26+
Usage string // Description for usage
27+
metaVar string // MetaVar for flag
28+
value FlagValue // Encapsulated parsing and value-setting logic
2929
}
3030

3131
func (f *Flag) MetaVar(metaVar string) {
@@ -35,15 +35,15 @@ func (f *Flag) MetaVar(metaVar string) {
3535
// FlagValue interface encapsulates parsing and value-setting logic
3636
type FlagValue interface {
3737
// Parse parses the given string value into the flag's value type
38-
Parse(value string) (interface{}, error)
38+
Parse(value string) (any, error)
3939
// Set sets the flag's value to the given value
40-
Set(value interface{}) error
40+
Set(value any) error
4141
// GetBound returns the bound value of the flag.
42-
GetBound() interface{}
42+
GetBound() any
4343
}
4444

4545
// Value returns the current value of the flag.
46-
func (f *Flag) GetValue() interface{} {
46+
func (f *Flag) GetValue() any {
4747
if f == nil || f.value == nil {
4848
return nil
4949
}

flags_parsed.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ type IdentifiersMap map[string]*ParsedGroup
88

99
// ParsedGroup represents a runtime group with parsed values.
1010
type ParsedGroup struct {
11-
Parent *ConfigGroup // Reference to the parent static group.
12-
Name string // Identifier for the child group (e.g., "IDENTIFIER1").
13-
Values map[string]interface{} // Parsed values for the group's flags.
11+
Parent *ConfigGroup // Reference to the parent static group.
12+
Name string // Identifier for the child group (e.g., "IDENTIFIER1").
13+
Values map[string]any // Parsed values for the group's flags.
1414
}
1515

1616
// Lookup retrieves the value of a flag in the parsed group.
17-
func (g *ParsedGroup) Lookup(flagName string) interface{} {
17+
func (g *ParsedGroup) Lookup(flagName string) any {
1818
if g == nil {
1919
return nil
2020
}

0 commit comments

Comments
 (0)