go-by-test/blogposts/blogposts.go

22 lines
358 B
Go

package blogposts
import (
"io/fs"
)
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())
if err != nil {
return nil, err
}
posts = append(posts, post)
}
return posts, nil
}