From 41dc86eb62b0ea44e69aff45f06e451c0b352bea Mon Sep 17 00:00:00 2001 From: Maxim Lebedev Date: Sun, 19 Nov 2023 14:11:26 +0600 Subject: [PATCH] :fire: Removed Fetch repository method in static module --- internal/static/repository.go | 7 ---- internal/static/repository/fs/fs_static.go | 39 ---------------------- 2 files changed, 46 deletions(-) diff --git a/internal/static/repository.go b/internal/static/repository.go index cbbcbeb..a6b3863 100644 --- a/internal/static/repository.go +++ b/internal/static/repository.go @@ -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 -} diff --git a/internal/static/repository/fs/fs_static.go b/internal/static/repository/fs/fs_static.go index adb5609..f1ec7df 100644 --- a/internal/static/repository/fs/fs_static.go +++ b/internal/static/repository/fs/fs_static.go @@ -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 -}