// glob searches for files matching pattern in the directory dir // and appends them to matches. If the directory cannot be // opened, it returns the existing matches. New matches are // added in lexicographical order. func glob(fs vfs.FileSystem, dir, pattern string, matches []string) (m []string, e error) { m = matches fi, err := fs.Stat(dir) if err != nil { return } if !fi.IsDir() { return } fis, err := fs.ReadDir(dir) if err != nil { return } sort.Sort(byName(fis)) for _, fi := range fis { n := fi.Name() matched, err := path.Match(path.Clean(pattern), n) if err != nil { return m, err } if matched { m = append(m, path.Join(dir, n)) } } return }
func readJSONFileFS(fs vfs.FileSystem, file string, v interface{}) (err error) { fi, err := fs.Stat(file) if err != nil { return err } if fi.Size() < 1 { return errEmptyJSONFile } f, err := fs.Open(file) if err != nil { return err } defer func() { err2 := f.Close() if err == nil { err = err2 } }() return json.NewDecoder(f).Decode(v) }