🔥 Removed Fetch repository method in static module

This commit is contained in:
Maxim Lebedev 2023-11-19 14:11:26 +06:00
parent 393d7e0fad
commit 41dc86eb62
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
2 changed files with 0 additions and 46 deletions

View File

@ -10,9 +10,6 @@ type (
Repository interface {
// Get returns Static on path if exists
Get(ctx context.Context, path string) (*domain.Static, error)
// Fetch returns all resources from dir recursevly.
Fetch(ctx context.Context, pattern string) ([]*domain.Static, int, error)
}
dummyRepository struct{}
@ -25,7 +22,3 @@ func NewDummyRepository() dummyRepository {
func (dummyRepository) Get(ctx context.Context, path string) (*domain.Static, error) {
return nil, nil
}
func (dummyRepository) Fetch(ctx context.Context, pattern string) ([]*domain.Static, int, error) {
return nil, 0, nil
}

View File

@ -46,42 +46,3 @@ func (repo *fileServerStaticRepository) Get(ctx context.Context, p string) (*dom
return domain.NewStatic(bytes.NewReader(content), info.ModTime(), info.Name()), nil
}
func (repo *fileServerStaticRepository) Fetch(ctx context.Context, pattern string) ([]*domain.Static, int, error) {
var (
err error
matches []string
)
if pattern != "" {
if matches, err = fs.Glob(repo.root, pattern); err != nil {
return nil, 0, fmt.Errorf("cannot match any static by pattern '%s': %w", pattern, err)
}
} else {
if err = fs.WalkDir(repo.root, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return fmt.Errorf("catched error while walk: %w", err)
}
if d.IsDir() {
return nil
}
matches = append(matches, path)
return nil
}); err != nil {
return nil, 0, fmt.Errorf("cannot walk through static directories: %w", err)
}
}
out := make([]*domain.Static, 0, len(matches))
for i := range matches {
if s, err := repo.Get(ctx, matches[i]); err == nil {
out = append(out, s)
}
}
return out, len(out), nil
}