From acb0d5e00c0b19e149eef429881b998414555a5d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 3 Nov 2024 11:45:19 +0200 Subject: refaxtor --- internal/queue/queue.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'internal/queue') diff --git a/internal/queue/queue.go b/internal/queue/queue.go index 526f43e..87aae65 100644 --- a/internal/queue/queue.go +++ b/internal/queue/queue.go @@ -5,7 +5,6 @@ import ( "log" "os" "path/filepath" - "slices" "strings" "time" @@ -30,11 +29,7 @@ func Run(args config.Args) error { // Queue all *.txt into ./db/*.txt.STAMP.queued func queueEntries(args config.Args) error { - // TODO: Use find(...), but refactor with variadic args - ch, err := oi.ReadDirCh(args.GosDir, func(file os.DirEntry) (string, bool) { - filePath := filepath.Join(args.GosDir, file.Name()) - return filePath, slices.Contains(validExtensions, filepath.Ext(file.Name())) && file.Type().IsRegular() - }) + ch, err := oi.ReadDirCh(args.GosDir, find(args.GosDir, validExtensions...)) if err != nil { return err } @@ -146,9 +141,14 @@ func deleteFiles(path, suffix string, olderThan time.Time) error { return nil } -func find(path, suffix string) func(os.DirEntry) (string, bool) { +func find(path string, suffixes ...string) func(os.DirEntry) (string, bool) { return func(file os.DirEntry) (string, bool) { filePath := filepath.Join(path, file.Name()) - return filePath, strings.HasSuffix(file.Name(), suffix) + for _, suffix := range suffixes { + if strings.HasSuffix(file.Name(), suffix) { + return filePath, true + } + } + return filePath, false } } -- cgit v1.2.3