Skip to content

Instantly share code, notes, and snippets.

@DesignFront
Created March 4, 2021 09:52
Show Gist options
  • Save DesignFront/edd93b9ec1184003132a431ccdfef854 to your computer and use it in GitHub Desktop.
Save DesignFront/edd93b9ec1184003132a431ccdfef854 to your computer and use it in GitHub Desktop.
goland: detect files in folder
func getFilesInPath(rootPath string, fileType string) ([]FileObj, error) {
var files []FileObj
err := filepath.Walk(rootPath, func(path string, info os.FileInfo, err error) error {
// read file
if err != nil {
fmt.Print(err)
}
subStr := strings.Replace(path, "testdata/", "", -1)
data, err := ioutil.ReadFile(subStr)
if err != nil {
fmt.Print(err)
}
var obj DocumentTruth
json.Unmarshal(data, &obj)
if strings.HasSuffix(path, fileType) {
files = append(files, FileObj{Path: subStr, Data: obj})
}
return nil
})
if err != nil {
panic(err)
}
return files, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment