Skip to content

Commit b3d8c3b

Browse files
committed
Ran go modernize
Morphs Interface{} to any Ranges over SplitSeq and FieldSeq for iterating splits Used min for end calculation remote_mount.Read Used range 16 in wol.createMagicPacket DID NOT apply the Omitempty cleanup.
1 parent 0ef6018 commit b3d8c3b

File tree

19 files changed

+97
-100
lines changed

19 files changed

+97
-100
lines changed

display.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const (
3030
// do not call this function directly, use switchToScreenIfDifferent instead
3131
// this function is not thread safe
3232
func switchToScreen(screen string) {
33-
_, err := CallCtrlAction("lv_scr_load", map[string]interface{}{"obj": screen})
33+
_, err := CallCtrlAction("lv_scr_load", map[string]any{"obj": screen})
3434
if err != nil {
3535
displayLogger.Warn().Err(err).Str("screen", screen).Msg("failed to switch to screen")
3636
return
@@ -39,15 +39,15 @@ func switchToScreen(screen string) {
3939
}
4040

4141
func lvObjSetState(objName string, state string) (*CtrlResponse, error) {
42-
return CallCtrlAction("lv_obj_set_state", map[string]interface{}{"obj": objName, "state": state})
42+
return CallCtrlAction("lv_obj_set_state", map[string]any{"obj": objName, "state": state})
4343
}
4444

4545
func lvObjAddFlag(objName string, flag string) (*CtrlResponse, error) {
46-
return CallCtrlAction("lv_obj_add_flag", map[string]interface{}{"obj": objName, "flag": flag})
46+
return CallCtrlAction("lv_obj_add_flag", map[string]any{"obj": objName, "flag": flag})
4747
}
4848

4949
func lvObjClearFlag(objName string, flag string) (*CtrlResponse, error) {
50-
return CallCtrlAction("lv_obj_clear_flag", map[string]interface{}{"obj": objName, "flag": flag})
50+
return CallCtrlAction("lv_obj_clear_flag", map[string]any{"obj": objName, "flag": flag})
5151
}
5252

5353
func lvObjHide(objName string) (*CtrlResponse, error) {
@@ -59,27 +59,27 @@ func lvObjShow(objName string) (*CtrlResponse, error) {
5959
}
6060

6161
func lvObjSetOpacity(objName string, opacity int) (*CtrlResponse, error) { // nolint:unused
62-
return CallCtrlAction("lv_obj_set_style_opa_layered", map[string]interface{}{"obj": objName, "opa": opacity})
62+
return CallCtrlAction("lv_obj_set_style_opa_layered", map[string]any{"obj": objName, "opa": opacity})
6363
}
6464

6565
func lvObjFadeIn(objName string, duration uint32) (*CtrlResponse, error) {
66-
return CallCtrlAction("lv_obj_fade_in", map[string]interface{}{"obj": objName, "time": duration})
66+
return CallCtrlAction("lv_obj_fade_in", map[string]any{"obj": objName, "time": duration})
6767
}
6868

6969
func lvObjFadeOut(objName string, duration uint32) (*CtrlResponse, error) {
70-
return CallCtrlAction("lv_obj_fade_out", map[string]interface{}{"obj": objName, "time": duration})
70+
return CallCtrlAction("lv_obj_fade_out", map[string]any{"obj": objName, "time": duration})
7171
}
7272

7373
func lvLabelSetText(objName string, text string) (*CtrlResponse, error) {
74-
return CallCtrlAction("lv_label_set_text", map[string]interface{}{"obj": objName, "text": text})
74+
return CallCtrlAction("lv_label_set_text", map[string]any{"obj": objName, "text": text})
7575
}
7676

7777
func lvImgSetSrc(objName string, src string) (*CtrlResponse, error) {
78-
return CallCtrlAction("lv_img_set_src", map[string]interface{}{"obj": objName, "src": src})
78+
return CallCtrlAction("lv_img_set_src", map[string]any{"obj": objName, "src": src})
7979
}
8080

8181
func lvDispSetRotation(rotation string) (*CtrlResponse, error) {
82-
return CallCtrlAction("lv_disp_set_rotation", map[string]interface{}{"rotation": rotation})
82+
return CallCtrlAction("lv_disp_set_rotation", map[string]any{"rotation": rotation})
8383
}
8484

8585
func updateLabelIfChanged(objName string, newText string) {

internal/confparser/confparser.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ import (
1616
type FieldConfig struct {
1717
Name string
1818
Required bool
19-
RequiredIf map[string]interface{}
19+
RequiredIf map[string]any
2020
OneOf []string
2121
ValidateTypes []string
22-
Defaults interface{}
22+
Defaults any
2323
IsEmpty bool
24-
CurrentValue interface{}
24+
CurrentValue any
2525
TypeString string
2626
Delegated bool
2727
shouldUpdateValue bool
2828
}
2929

30-
func SetDefaultsAndValidate(config interface{}) error {
30+
func SetDefaultsAndValidate(config any) error {
3131
return setDefaultsAndValidate(config, true)
3232
}
3333

34-
func setDefaultsAndValidate(config interface{}, isRoot bool) error {
34+
func setDefaultsAndValidate(config any, isRoot bool) error {
3535
// first we need to check if the config is a pointer
3636
if reflect.TypeOf(config).Kind() != reflect.Ptr {
3737
return fmt.Errorf("config is not a pointer")
@@ -55,7 +55,7 @@ func setDefaultsAndValidate(config interface{}, isRoot bool) error {
5555
Name: field.Name,
5656
OneOf: splitString(field.Tag.Get("one_of")),
5757
ValidateTypes: splitString(field.Tag.Get("validate_type")),
58-
RequiredIf: make(map[string]interface{}),
58+
RequiredIf: make(map[string]any),
5959
CurrentValue: fieldValue.Interface(),
6060
IsEmpty: false,
6161
TypeString: fieldType,
@@ -142,8 +142,8 @@ func setDefaultsAndValidate(config interface{}, isRoot bool) error {
142142
// now check if the field has required_if
143143
requiredIf := field.Tag.Get("required_if")
144144
if requiredIf != "" {
145-
requiredIfParts := strings.Split(requiredIf, ",")
146-
for _, part := range requiredIfParts {
145+
requiredIfParts := strings.SplitSeq(requiredIf, ",")
146+
for part := range requiredIfParts {
147147
partVal := strings.SplitN(part, "=", 2)
148148
if len(partVal) != 2 {
149149
return fmt.Errorf("invalid required_if for field `%s`: %s", field.Name, requiredIf)
@@ -168,7 +168,7 @@ func setDefaultsAndValidate(config interface{}, isRoot bool) error {
168168
return nil
169169
}
170170

171-
func validateFields(config interface{}, fields map[string]FieldConfig) error {
171+
func validateFields(config any, fields map[string]FieldConfig) error {
172172
// now we can start to validate the fields
173173
for _, fieldConfig := range fields {
174174
if err := fieldConfig.validate(fields); err != nil {
@@ -215,7 +215,7 @@ func (f *FieldConfig) validate(fields map[string]FieldConfig) error {
215215
return nil
216216
}
217217

218-
func (f *FieldConfig) populate(config interface{}) {
218+
func (f *FieldConfig) populate(config any) {
219219
// update the field if it's not empty
220220
if !f.shouldUpdateValue {
221221
return

internal/confparser/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func splitString(s string) []string {
1616
return strings.Split(s, ",")
1717
}
1818

19-
func toString(v interface{}) (string, error) {
19+
func toString(v any) (string, error) {
2020
switch v := v.(type) {
2121
case string:
2222
return v, nil

internal/logging/logger.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var (
5050
TimeFormat: time.RFC3339,
5151
PartsOrder: []string{"time", "level", "scope", "component", "message"},
5252
FieldsExclude: []string{"scope", "component"},
53-
FormatPartValueByName: func(value interface{}, name string) string {
53+
FormatPartValueByName: func(value any, name string) string {
5454
val := fmt.Sprintf("%s", value)
5555
if name == "component" {
5656
if value == nil {
@@ -121,8 +121,8 @@ func (l *Logger) updateLogLevel() {
121121
continue
122122
}
123123

124-
scopes := strings.Split(strings.ToLower(env), ",")
125-
for _, scope := range scopes {
124+
scopes := strings.SplitSeq(strings.ToLower(env), ",")
125+
for scope := range scopes {
126126
l.scopeLevels[scope] = level
127127
}
128128
}

internal/logging/pion.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,32 @@ type pionLogger struct {
1313
func (c pionLogger) Trace(msg string) {
1414
c.logger.Trace().Msg(msg)
1515
}
16-
func (c pionLogger) Tracef(format string, args ...interface{}) {
16+
func (c pionLogger) Tracef(format string, args ...any) {
1717
c.logger.Trace().Msgf(format, args...)
1818
}
1919

2020
func (c pionLogger) Debug(msg string) {
2121
c.logger.Debug().Msg(msg)
2222
}
23-
func (c pionLogger) Debugf(format string, args ...interface{}) {
23+
func (c pionLogger) Debugf(format string, args ...any) {
2424
c.logger.Debug().Msgf(format, args...)
2525
}
2626
func (c pionLogger) Info(msg string) {
2727
c.logger.Info().Msg(msg)
2828
}
29-
func (c pionLogger) Infof(format string, args ...interface{}) {
29+
func (c pionLogger) Infof(format string, args ...any) {
3030
c.logger.Info().Msgf(format, args...)
3131
}
3232
func (c pionLogger) Warn(msg string) {
3333
c.logger.Warn().Msg(msg)
3434
}
35-
func (c pionLogger) Warnf(format string, args ...interface{}) {
35+
func (c pionLogger) Warnf(format string, args ...any) {
3636
c.logger.Warn().Msgf(format, args...)
3737
}
3838
func (c pionLogger) Error(msg string) {
3939
c.logger.Error().Msg(msg)
4040
}
41-
func (c pionLogger) Errorf(format string, args ...interface{}) {
41+
func (c pionLogger) Errorf(format string, args ...any) {
4242
c.logger.Error().Msgf(format, args...)
4343
}
4444

internal/logging/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func GetDefaultLogger() *zerolog.Logger {
1313
return &defaultLogger
1414
}
1515

16-
func ErrorfL(l *zerolog.Logger, format string, err error, args ...interface{}) error {
16+
func ErrorfL(l *zerolog.Logger, format string, err error, args ...any) error {
1717
// TODO: move rootLogger to logging package
1818
if l == nil {
1919
l = &defaultLogger

internal/network/hostname.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func updateEtcHosts(hostname string, fqdn string) error {
4242
hostLine := fmt.Sprintf("127.0.1.1\t%s %s", hostname, fqdn)
4343
hostLineExists := false
4444

45-
for _, line := range strings.Split(string(lines), "\n") {
45+
for line := range strings.SplitSeq(string(lines), "\n") {
4646
if strings.HasPrefix(line, "127.0.1.1") {
4747
hostLineExists = true
4848
line = hostLine

internal/network/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func lifetimeToTime(lifetime int) *time.Time {
1313
return &t
1414
}
1515

16-
func IsSame(a, b interface{}) bool {
16+
func IsSame(a, b any) bool {
1717
aJSON, err := json.Marshal(a)
1818
if err != nil {
1919
return false

internal/udhcpc/parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (l *Lease) SetLeaseExpiry() (time.Time, error) {
101101
func UnmarshalDHCPCLease(lease *Lease, str string) error {
102102
// parse the lease file as a map
103103
data := make(map[string]string)
104-
for _, line := range strings.Split(str, "\n") {
104+
for line := range strings.SplitSeq(str, "\n") {
105105
line = strings.TrimSpace(line)
106106
// skip empty lines and comments
107107
if line == "" || strings.HasPrefix(line, "#") {
@@ -165,7 +165,7 @@ func UnmarshalDHCPCLease(lease *Lease, str string) error {
165165
field.Set(reflect.ValueOf(ip))
166166
case []net.IP:
167167
val := make([]net.IP, 0)
168-
for _, ipStr := range strings.Fields(value) {
168+
for ipStr := range strings.FieldsSeq(value) {
169169
ip := net.ParseIP(ipStr)
170170
if ip == nil {
171171
continue

internal/udhcpc/udhcpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func NewDHCPClient(options *DHCPClientOptions) *DHCPClient {
5252
}
5353

5454
func (c *DHCPClient) getWatchPaths() []string {
55-
watchPaths := make(map[string]interface{})
55+
watchPaths := make(map[string]any)
5656
watchPaths[filepath.Dir(c.leaseFile)] = nil
5757

5858
if c.pidFile != "" {

0 commit comments

Comments
 (0)