/
githubmirror
/
photoprism
Обзор
Документация
Войти
/
githubmirror
/
photoprism
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
pkg/fs/readlines.go
38 строк
628 B
Michael Mayer
Backend: Clean up error handling and unit tests in pkg/...
09 фев 2026, 14:31
09 фев 2026, 14:31
df5efb6
Код
Авторство
О чём код?
package fs import ( "bufio" "errors" "io" "os" "strings" ) // ReadLines returns all lines in a text file as string slice. func ReadLines(fileName string) (lines []string, err error) { file, err := os.Open(fileName) //nolint:gosec // caller-controlled path; intended file read if err != nil { return lines, err } defer func() { err = errors.Join(err, file.Close()) }() reader := bufio.NewReader(file) for { line, _, err := reader.ReadLine() if err == io.EOF { break } else if err != nil { return lines, err } lines = append(lines, strings.TrimSpace(string(line))) } return lines, nil }