🏷️ Created and used Files slice type
This commit is contained in:
parent
f3c4118286
commit
74b41b972b
|
@ -0,0 +1,4 @@
|
|||
package domain
|
||||
|
||||
// TODO(toby3d): search by glob pattern, type or name/id.
|
||||
type Files []*File
|
|
@ -7,5 +7,5 @@ type Page struct {
|
|||
Params map[string]any
|
||||
Title string
|
||||
Content []byte
|
||||
Files []*File
|
||||
Files Files
|
||||
}
|
||||
|
|
|
@ -11,5 +11,5 @@ type Site struct {
|
|||
TimeZone *time.Location
|
||||
Params map[string]any
|
||||
Title string
|
||||
Files []*File
|
||||
Files Files
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
type (
|
||||
Repository interface {
|
||||
Get(ctx context.Context, path string) (*domain.File, error)
|
||||
Fetch(ctx context.Context, dir string) ([]*domain.File, int, error)
|
||||
Fetch(ctx context.Context, dir string) (domain.Files, int, error)
|
||||
}
|
||||
|
||||
dummyRepository struct{}
|
||||
|
@ -20,6 +20,7 @@ func NewDummyRepository() dummyRepository {
|
|||
}
|
||||
|
||||
func (dummyRepository) Get(ctx context.Context, path string) (*domain.File, error) { return nil, nil }
|
||||
func (dummyRepository) Fetch(ctx context.Context, dir string) ([]*domain.File, int, error) {
|
||||
|
||||
func (dummyRepository) Fetch(ctx context.Context, dir string) (domain.Files, int, error) {
|
||||
return nil, 0, nil
|
||||
}
|
||||
|
|
|
@ -38,13 +38,13 @@ func (repo *fileServerStaticRepository) Get(ctx context.Context, p string) (*dom
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (repo *fileServerStaticRepository) Fetch(ctx context.Context, d string) ([]*domain.File, int, error) {
|
||||
func (repo *fileServerStaticRepository) Fetch(ctx context.Context, d string) (domain.Files, int, error) {
|
||||
entries, err := fs.ReadDir(repo.root, d)
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("cannot read directory on path '%s': %w", d, err)
|
||||
}
|
||||
|
||||
out := make([]*domain.File, 0, len(entries))
|
||||
out := make(domain.Files, 0, len(entries))
|
||||
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() {
|
||||
|
|
Loading…
Reference in New Issue