1package chartify 2 3import ( 4 "os" 5 "strings" 6) 7 8type SearchFileOpts struct { 9 basePath string 10 matchSubPath string 11 fileType string 12} 13 14// SearchFiles returns a slice of files that are within the base path, has a matching sub path and file type 15func (r *Runner) SearchFiles(o SearchFileOpts) ([]string, error) { 16 var files []string 17 18 err := r.Walk(o.basePath, func(path string, info os.FileInfo, err error) error { 19 if !strings.Contains(path, o.matchSubPath+"/") { 20 return nil 21 } 22 if !strings.HasSuffix(path, o.fileType) { 23 return nil 24 } 25 files = append(files, path) 26 return nil 27 }) 28 29 if err != nil { 30 return nil, err 31 } 32 33 return files, nil 34} 35