Skip to content

Commit 241cf55

Browse files
committed
chore modernize
1 parent 2105391 commit 241cf55

File tree

12 files changed

+102
-105
lines changed

12 files changed

+102
-105
lines changed

internal/cache/cache.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
)
1010

1111
type Cache struct {
12-
Expiration time.Time `json:"expiration"`
13-
Data interface{} `json:"data"`
12+
Expiration time.Time `json:"expiration"`
13+
Data any `json:"data"`
1414
}
1515

16-
func New(ttl time.Duration, data interface{}) *Cache {
16+
func New(ttl time.Duration, data any) *Cache {
1717
return &Cache{
1818
Expiration: time.Now().Add(ttl),
1919
Data: data,
@@ -24,7 +24,7 @@ func (c *Cache) Expired() bool {
2424
return time.Now().After(c.Expiration)
2525
}
2626

27-
func (c *Cache) Bind(dst interface{}) error {
27+
func (c *Cache) Bind(dst any) error {
2828
if err := mapstructure.Decode(c.Data, dst); err != nil {
2929
return err
3030
}

internal/cache/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (s *Store) Get(key string) (*Cache, error) {
4646
return c, nil
4747
}
4848

49-
func (s *Store) Set(key string, data interface{}) error {
49+
func (s *Store) Set(key string, data any) error {
5050
p := s.buildPath(key)
5151

5252
f, err := util.CreateFile(p)

internal/config/action.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (action *ScreenshotAction) String() string {
8686
return "Take a screenshot"
8787
}
8888

89-
var parseFuncMap = map[string]func(*Settings, map[string]interface{}) (Action, error){
89+
var parseFuncMap = map[string]func(*Settings, map[string]any) (Action, error){
9090
"type": parseTypeAction,
9191
"key": parseKeyAction,
9292
"ctrl": parseCtrlAction,
@@ -95,16 +95,16 @@ var parseFuncMap = map[string]func(*Settings, map[string]interface{}) (Action, e
9595
"screenshot": parseScreenshotAction,
9696
}
9797

98-
func ParseAction(stgs *Settings, v interface{}) (Action, error) {
98+
func ParseAction(stgs *Settings, v any) (Action, error) {
9999
switch v := v.(type) {
100100
case string:
101101
switch v {
102102
case "pause":
103-
return parsePauseAction(stgs, map[string]interface{}{})
103+
return parsePauseAction(stgs, map[string]any{})
104104
case "screenshot":
105-
return parseScreenshotAction(stgs, map[string]interface{}{})
105+
return parseScreenshotAction(stgs, map[string]any{})
106106
}
107-
case map[string]interface{}:
107+
case map[string]any:
108108
for _, k := range []string{"type", "key", "ctrl", "sleep", "pause", "screenshot"} {
109109
if _, ok := v[k]; ok {
110110
return parseFuncMap[k](stgs, v)
@@ -115,7 +115,7 @@ func ParseAction(stgs *Settings, v interface{}) (Action, error) {
115115
return nil, NewErrInvalidAction(v)
116116
}
117117

118-
func parseTypeAction(stgs *Settings, m map[string]interface{}) (Action, error) {
118+
func parseTypeAction(stgs *Settings, m map[string]any) (Action, error) {
119119
if err := validateActionFields(m, typeActionValidFields); err != nil {
120120
return nil, err
121121
}
@@ -131,7 +131,7 @@ func parseTypeAction(stgs *Settings, m map[string]interface{}) (Action, error) {
131131
return &action, nil
132132
}
133133

134-
func parseKeyAction(settings *Settings, m map[string]interface{}) (Action, error) {
134+
func parseKeyAction(settings *Settings, m map[string]any) (Action, error) {
135135
if err := validateActionFields(m, keyActionValidFields); err != nil {
136136
return nil, err
137137
}
@@ -156,7 +156,7 @@ func parseKeyAction(settings *Settings, m map[string]interface{}) (Action, error
156156
return &action, nil
157157
}
158158

159-
func parseSleepAction(settings *Settings, m map[string]interface{}) (Action, error) {
159+
func parseSleepAction(settings *Settings, m map[string]any) (Action, error) {
160160
if err := validateActionFields(m, sleepActionValidFields); err != nil {
161161
return nil, err
162162
}
@@ -169,15 +169,15 @@ func parseSleepAction(settings *Settings, m map[string]interface{}) (Action, err
169169
return &action, nil
170170
}
171171

172-
func parsePauseAction(settings *Settings, m map[string]interface{}) (Action, error) {
172+
func parsePauseAction(settings *Settings, m map[string]any) (Action, error) {
173173
if err := validateActionFields(m, pauseActionValidFields); err != nil {
174174
return nil, err
175175
}
176176

177177
return &PauseAction{}, nil
178178
}
179179

180-
func parseCtrlAction(settings *Settings, m map[string]interface{}) (Action, error) {
180+
func parseCtrlAction(settings *Settings, m map[string]any) (Action, error) {
181181
if err := validateActionFields(m, ctrlActionValidFields); err != nil {
182182
return nil, err
183183
}
@@ -193,7 +193,7 @@ func parseCtrlAction(settings *Settings, m map[string]interface{}) (Action, erro
193193
return &action, nil
194194
}
195195

196-
func parseScreenshotAction(settings *Settings, m map[string]interface{}) (Action, error) {
196+
func parseScreenshotAction(settings *Settings, m map[string]any) (Action, error) {
197197
if err := validateActionFields(m, screenshotActionValidFields); err != nil {
198198
return nil, err
199199
}
@@ -208,7 +208,7 @@ func parseScreenshotAction(settings *Settings, m map[string]interface{}) (Action
208208
return &action, nil
209209
}
210210

211-
func validateActionFields(m map[string]interface{}, valid []string) error {
211+
func validateActionFields(m map[string]any, valid []string) error {
212212
invalidFields := []string{}
213213
for k := range m {
214214
if !util.Contains(valid, k) {

internal/config/action_test.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -164,32 +164,32 @@ func Test_parseTypeAction(t *testing.T) {
164164
stgs := &Settings{DefaultSpeed: 10}
165165

166166
tests := []struct {
167-
input map[string]interface{}
167+
input map[string]any
168168
want Action
169169
wantErr bool
170170
}{
171171
{
172-
map[string]interface{}{"type": "Hello World"},
172+
map[string]any{"type": "Hello World"},
173173
&TypeAction{Type: "Hello World", Count: 1, Speed: stgs.DefaultSpeed},
174174
false,
175175
},
176176
{
177-
map[string]interface{}{"type": "Hello World", "count": 10},
177+
map[string]any{"type": "Hello World", "count": 10},
178178
&TypeAction{Type: "Hello World", Count: 10, Speed: stgs.DefaultSpeed},
179179
false,
180180
},
181181
{
182-
map[string]interface{}{"type": "Hello World", "speed": 500},
182+
map[string]any{"type": "Hello World", "speed": 500},
183183
&TypeAction{Type: "Hello World", Count: 1, Speed: 500},
184184
false,
185185
},
186186
{
187-
map[string]interface{}{"type": "Hello World", "count": 10, "speed": 500},
187+
map[string]any{"type": "Hello World", "count": 10, "speed": 500},
188188
&TypeAction{Type: "Hello World", Count: 10, Speed: 500},
189189
false,
190190
},
191191
{
192-
map[string]interface{}{"type": "Hello World", "a": "A"},
192+
map[string]any{"type": "Hello World", "a": "A"},
193193
nil,
194194
true,
195195
},
@@ -211,32 +211,32 @@ func Test_parseKeyAction(t *testing.T) {
211211
stgs := &Settings{DefaultSpeed: 10}
212212

213213
tests := []struct {
214-
input map[string]interface{}
214+
input map[string]any
215215
want Action
216216
wantErr bool
217217
}{
218218
{
219-
map[string]interface{}{"key": "enter"},
219+
map[string]any{"key": "enter"},
220220
&KeyAction{Key: "enter", Count: 1, Speed: stgs.DefaultSpeed},
221221
false,
222222
},
223223
{
224-
map[string]interface{}{"key": "enter", "count": 10},
224+
map[string]any{"key": "enter", "count": 10},
225225
&KeyAction{Key: "enter", Count: 10, Speed: stgs.DefaultSpeed},
226226
false,
227227
},
228228
{
229-
map[string]interface{}{"key": "enter", "speed": 500},
229+
map[string]any{"key": "enter", "speed": 500},
230230
&KeyAction{Key: "enter", Count: 1, Speed: 500},
231231
false,
232232
},
233233
{
234-
map[string]interface{}{"key": "enter", "count": 10, "speed": 500},
234+
map[string]any{"key": "enter", "count": 10, "speed": 500},
235235
&KeyAction{Key: "enter", Count: 10, Speed: 500},
236236
false,
237237
},
238238
{
239-
map[string]interface{}{"key": "enter", "a": "A"},
239+
map[string]any{"key": "enter", "a": "A"},
240240
nil,
241241
true,
242242
},
@@ -256,17 +256,17 @@ func Test_parseKeyAction(t *testing.T) {
256256

257257
func Test_parseSleepAction(t *testing.T) {
258258
tests := []struct {
259-
input map[string]interface{}
259+
input map[string]any
260260
want Action
261261
wantErr bool
262262
}{
263263
{
264-
map[string]interface{}{"sleep": 3000},
264+
map[string]any{"sleep": 3000},
265265
&SleepAction{Sleep: 3000},
266266
false,
267267
},
268268
{
269-
map[string]interface{}{"sleep": 3000, "a": "A"},
269+
map[string]any{"sleep": 3000, "a": "A"},
270270
nil,
271271
true,
272272
},
@@ -286,22 +286,22 @@ func Test_parseSleepAction(t *testing.T) {
286286

287287
func Test_parsePauseAction(t *testing.T) {
288288
tests := []struct {
289-
input map[string]interface{}
289+
input map[string]any
290290
want Action
291291
wantErr bool
292292
}{
293293
{
294-
map[string]interface{}{"pause": nil},
294+
map[string]any{"pause": nil},
295295
&PauseAction{},
296296
false,
297297
},
298298
{
299-
map[string]interface{}{"pause": struct{}{}},
299+
map[string]any{"pause": struct{}{}},
300300
&PauseAction{},
301301
false,
302302
},
303303
{
304-
map[string]interface{}{"pause": nil, "a": "A"},
304+
map[string]any{"pause": nil, "a": "A"},
305305
nil,
306306
true,
307307
},
@@ -323,32 +323,32 @@ func Test_parseCtrlAction(t *testing.T) {
323323
stgs := &Settings{DefaultSpeed: 10}
324324

325325
tests := []struct {
326-
input map[string]interface{}
326+
input map[string]any
327327
want Action
328328
wantErr bool
329329
}{
330330
{
331-
map[string]interface{}{"ctrl": "c"},
331+
map[string]any{"ctrl": "c"},
332332
&CtrlAction{Ctrl: "c", Count: 1, Speed: 10},
333333
false,
334334
},
335335
{
336-
map[string]interface{}{"ctrl": "c", "count": 10},
336+
map[string]any{"ctrl": "c", "count": 10},
337337
&CtrlAction{Ctrl: "c", Count: 10, Speed: stgs.DefaultSpeed},
338338
false,
339339
},
340340
{
341-
map[string]interface{}{"ctrl": "c", "speed": 500},
341+
map[string]any{"ctrl": "c", "speed": 500},
342342
&CtrlAction{Ctrl: "c", Count: 1, Speed: 500},
343343
false,
344344
},
345345
{
346-
map[string]interface{}{"ctrl": "c", "count": 10, "speed": 500},
346+
map[string]any{"ctrl": "c", "count": 10, "speed": 500},
347347
&CtrlAction{Ctrl: "c", Count: 10, Speed: 500},
348348
false,
349349
},
350350
{
351-
map[string]interface{}{"ctrl": "c", "a": "A"},
351+
map[string]any{"ctrl": "c", "a": "A"},
352352
nil,
353353
true,
354354
},
@@ -368,22 +368,22 @@ func Test_parseCtrlAction(t *testing.T) {
368368

369369
func Test_parseScreenshotAction(t *testing.T) {
370370
tests := []struct {
371-
input map[string]interface{}
371+
input map[string]any
372372
want Action
373373
wantErr bool
374374
}{
375375
{
376-
map[string]interface{}{"screenshot": nil},
376+
map[string]any{"screenshot": nil},
377377
&ScreenshotAction{},
378378
false,
379379
},
380380
{
381-
map[string]interface{}{"screenshot": "SCREENSHOT"},
381+
map[string]any{"screenshot": "SCREENSHOT"},
382382
&ScreenshotAction{Screenshot: util.String("SCREENSHOT")},
383383
false,
384384
},
385385
{
386-
map[string]interface{}{"screenshot": nil, "a": "A"},
386+
map[string]any{"screenshot": nil, "a": "A"},
387387
nil,
388388
true,
389389
},

internal/config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
)
1212

1313
type configYaml struct {
14-
Settings map[string]interface{} `yaml:"settings"`
15-
Actions []interface{} `yaml:"actions"`
14+
Settings map[string]any `yaml:"settings"`
15+
Actions []any `yaml:"actions"`
1616
}
1717

1818
type Config struct {
@@ -36,7 +36,7 @@ func Load(name string) (*Config, error) {
3636
}
3737

3838
func Decode(r io.Reader) (*Config, error) {
39-
m := map[string]interface{}{}
39+
m := map[string]any{}
4040
if err := yaml.NewDecoder(r).Decode(&m); err != nil {
4141
return nil, err
4242
}
@@ -49,7 +49,7 @@ func Decode(r io.Reader) (*Config, error) {
4949
return cfg, nil
5050
}
5151

52-
func DecodeMap(m map[string]interface{}) (*Config, error) {
52+
func DecodeMap(m map[string]any) (*Config, error) {
5353
invalidFields := []string{}
5454
for k := range m {
5555
if !util.Contains([]string{"settings", "actions"}, k) {

0 commit comments

Comments
 (0)