go-by-test/blogposts/blogposts.go

22 lines
358 B
Go
Raw Normal View History

2024-09-23 21:09:10 +00:00
package blogposts
2024-09-24 18:57:28 +00:00
import (
"io/fs"
)
2024-09-23 21:09:10 +00:00
2024-09-24 18:57:28 +00:00
func NewPostsFromFS(fileSystem fs.FS) ([]Post, error) {
dir, err := fs.ReadDir(fileSystem, ".")
if err != nil {
return nil, err
}
var posts []Post
for _, f := range dir {
post, err := getPost(fileSystem, f.Name())
2024-09-24 18:57:28 +00:00
if err != nil {
return nil, err
}
posts = append(posts, post)
}
return posts, nil
}