summaryrefslogtreecommitdiff
path: root/internal/queue/queue.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-11-03 11:45:19 +0200
committerPaul Buetow <paul@buetow.org>2024-11-03 11:45:19 +0200
commitacb0d5e00c0b19e149eef429881b998414555a5d (patch)
tree73621172e3c9f2a6ba5aeb8b0bdc24e62a4107c3 /internal/queue/queue.go
parent85a818d03c1e442ef005b771a76ffb977c59fe75 (diff)
refaxtor
Diffstat (limited to 'internal/queue/queue.go')
-rw-r--r--internal/queue/queue.go16
1 files changed, 8 insertions, 8 deletions
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
}
}