Completed
Push — master ( 015fff...2fb069 )
by Valentin
02:25
created

etool/parse.go   A

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 21
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B etool.Parse 0 17 6
A etool.sourceFile 0 6 2
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