diff options
| -rw-r--r-- | Taskfile.yml | 5 | ||||
| -rw-r--r-- | internal/queue/queue.go | 16 |
2 files changed, 12 insertions, 9 deletions
diff --git a/Taskfile.yml b/Taskfile.yml index db64119..27e2323 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -32,6 +32,9 @@ tasks: lint: cmds: - golangci-lint run - lint-install: + dev-install: cmds: + - go install golang.org/x/tools/gopls@latest - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + + 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 } } |
