🏷️ Created and used Files slice type

This commit is contained in:
Maxim Lebedev 2023-11-09 06:57:05 +06:00
parent f3c4118286
commit 74b41b972b
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
5 changed files with 11 additions and 6 deletions

4
internal/domain/files.go Normal file
View File

@ -0,0 +1,4 @@
package domain
// TODO(toby3d): search by glob pattern, type or name/id.
type Files []*File

View File

@ -7,5 +7,5 @@ type Page struct {
Params map[string]any
Title string
Content []byte
Files []*File
Files Files
}

View File

@ -11,5 +11,5 @@ type Site struct {
TimeZone *time.Location
Params map[string]any
Title string
Files []*File
Files Files
}

View File

@ -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
}

View File

@ -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() {