MCPcopy
hub / github.com/cortexlabs/cortex / StructFromFiles

Function StructFromFiles

pkg/lib/configreader/reader.go:992–1009  ·  view source on GitHub ↗

Reads a directory of files into a struct, where each file name is the key and the contents is the value

(dest interface{}, dirPath string, v *StructValidation)

Source from the content-addressed store, hash-verified

990
991// Reads a directory of files into a struct, where each file name is the key and the contents is the value
992func StructFromFiles(dest interface{}, dirPath string, v *StructValidation) []error {
993 strMap := map[string]string{}
994
995 fileNames, err := files.ListDir(dirPath, true)
996 if err != nil {
997 return []error{err}
998 }
999
1000 for _, fileName := range fileNames {
1001 fileBytes, err := files.ReadFileBytes(filepath.Join(dirPath, fileName))
1002 if err != nil {
1003 return []error{err}
1004 }
1005 strMap[fileName] = strings.TrimSpace(string(fileBytes))
1006 }
1007
1008 return StructFromStringMap(dest, strMap, v)
1009}
1010
1011//
1012// Environment variable

Callers

nothing calls this directly

Calls 3

ListDirFunction · 0.92
ReadFileBytesFunction · 0.92
StructFromStringMapFunction · 0.85

Tested by

no test coverage detected