🔥 Removed Fetch repository method in static module
This commit is contained in:
parent
393d7e0fad
commit
41dc86eb62
|
@ -10,9 +10,6 @@ type (
|
||||||
Repository interface {
|
Repository interface {
|
||||||
// Get returns Static on path if exists
|
// Get returns Static on path if exists
|
||||||
Get(ctx context.Context, path string) (*domain.Static, error)
|
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{}
|
dummyRepository struct{}
|
||||||
|
@ -25,7 +22,3 @@ func NewDummyRepository() dummyRepository {
|
||||||
func (dummyRepository) Get(ctx context.Context, path string) (*domain.Static, error) {
|
func (dummyRepository) Get(ctx context.Context, path string) (*domain.Static, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dummyRepository) Fetch(ctx context.Context, pattern string) ([]*domain.Static, int, error) {
|
|
||||||
return nil, 0, nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -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
|
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
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue