Files
patchworks/src/modules/tasks/tasks.go
T
2026-03-30 16:58:19 +02:00

36 lines
635 B
Go

package tasks
import (
"log"
"os"
"strings"
)
func isYaml(filename string) bool {
return strings.HasSuffix(filename, ".yaml") || strings.HasSuffix(filename, ".yml")
}
func ListAvailableBooks() ([]string, error) {
files, err := os.ReadDir("./books")
if err != nil {
log.Printf("failed to read the './books' directory: %v", err)
return []string{}, err
}
foundBooks := []string{}
for _, f := range files {
if f.IsDir() {
continue
}
fName := f.Name()
log.Println(fName)
if isYaml(fName) {
fullRelPath := "./books/" + fName
foundBooks = append(foundBooks, fullRelPath)
}
}
return foundBooks, nil
}