Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
neumachen committed Jan 24, 2018
1 parent 2d33f79 commit b84e260
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,9 @@ func LoadFolders(folders ...string) (Store, error) {
return nil, err
}

switch mode := finfo.Mode(); {
case mode.IsDir():
files, err := lsFiles(fdir.Name())
if err != nil {
return nil, err
}
for _, f := range files {
file, err := os.Open(f)
if err != nil {
return nil, err
}
err = loadFile(s, file)
defer file.Close()
if err != nil {
return nil, err
}
}
case mode.IsRegular():
err := loadFile(s, fdir)
if err != nil {
return nil, err
}
err = loadFolder(fdir, finfo, s)
if err != nil {
return nil, err
}
}
return s, nil
Expand All @@ -93,30 +74,38 @@ func LoadFolder(folder string) (Store, error) {

s := &store{files: make(map[string]string)}

err = loadFolder(fdir, finfo, s)
if err != nil {
return nil, err
}
return s, nil
}

func loadFolder(fdir *os.File, finfo os.FileInfo, s *store) error {
switch mode := finfo.Mode(); {
case mode.IsDir():
files, err := lsFiles(fdir.Name())
if err != nil {
return nil, err
return err
}
for _, f := range files {
file, err := os.Open(f)
if err != nil {
return nil, err
return err
}
err = loadFile(s, file)
defer file.Close()
if err != nil {
return nil, err
return err
}
}
case mode.IsRegular():
err := loadFile(s, fdir)
if err != nil {
return nil, err
return err
}
}
return s, nil
return nil
}

// loadFile ...
Expand Down

0 comments on commit b84e260

Please sign in to comment.