| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package etool |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "encoding/json" |
||
| 5 | "github.com/vvval/go-metadata-scanner/vars" |
||
| 6 | "github.com/vvval/go-metadata-scanner/vars/metadata" |
||
| 7 | ) |
||
| 8 | |||
| 9 | const sourceFileField string = "SourceFile" |
||
| 10 | |||
| 11 | func Parse(data []byte) []vars.File { |
||
| 12 | var files []vars.File |
||
| 13 | var schema []metadata.Tags |
||
| 14 | |||
| 15 | if err := json.Unmarshal(data, &schema); err == nil { |
||
| 16 | for _, element := range schema { |
||
| 17 | if sf, ok := element[sourceFileField]; ok { |
||
| 18 | if filename, ok := sourceFile(sf); ok { |
||
| 19 | delete(element, sourceFileField) |
||
| 20 | file := vars.NewFile(filename, element) |
||
| 21 | files = append(files, file) |
||
| 22 | } |
||
| 23 | } |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | return files |
||
| 28 | } |
||
| 29 | |||
| 30 | func sourceFile(s interface{}) (string, bool) { |
||
| 31 | if filename, ok := s.(string); ok { |
||
| 32 | return filename, true |
||
| 33 | } |
||
| 34 | |||
| 35 | return "", false |
||
| 36 | } |
||
| 37 |