Created
March 4, 2021 09:52
-
-
Save DesignFront/edd93b9ec1184003132a431ccdfef854 to your computer and use it in GitHub Desktop.
goland: detect files in folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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