Total Lines | 58 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package config |
||
2 | |||
3 | import ( |
||
4 | "github.com/vvval/go-metadata-scanner/configuration" |
||
5 | "github.com/vvval/go-metadata-scanner/util" |
||
6 | "gopkg.in/yaml.v2" |
||
7 | ) |
||
8 | |||
9 | type AppConfig struct { |
||
10 | toolPath string |
||
11 | extensions []string |
||
12 | fields []string |
||
13 | } |
||
14 | |||
15 | type AppSchema struct { |
||
16 | ToolPath string `yaml:"exiftool"` |
||
17 | Extensions []string `yaml:"extensions"` |
||
18 | Fields []string `yaml:"fields"` |
||
19 | } |
||
20 | |||
21 | func (c AppConfig) MergeDefault(conf configuration.Config) configuration.Config { |
||
22 | if len(c.toolPath) == 0 { |
||
23 | c.toolPath = conf.(AppConfig).toolPath |
||
24 | } |
||
25 | |||
26 | c.extensions = util.UniqueValues(append(c.extensions, conf.(AppConfig).extensions...)) |
||
27 | c.fields = util.UniqueValues(append(c.fields, conf.(AppConfig).fields...)) |
||
28 | |||
29 | return c |
||
30 | } |
||
31 | |||
32 | func (c AppConfig) Schema() configuration.Schema { |
||
33 | return AppSchema{} |
||
34 | } |
||
35 | |||
36 | func (s AppSchema) Parse(data []byte) (configuration.Config, error) { |
||
37 | err := yaml.Unmarshal(data, &s) |
||
38 | if err != nil { |
||
39 | return AppConfig{}, err |
||
40 | } |
||
41 | |||
42 | return AppConfig{ |
||
43 | toolPath: s.ToolPath, |
||
44 | extensions: s.Extensions, |
||
45 | fields: s.Fields, |
||
46 | }, nil |
||
47 | } |
||
48 | |||
49 | func (c AppConfig) ToolPath() string { |
||
50 | return c.toolPath |
||
51 | } |
||
52 | |||
53 | func (c AppConfig) Extensions() []string { |
||
54 | return c.extensions |
||
55 | } |
||
56 | |||
57 | func (c AppConfig) Fields() []string { |
||
58 | return c.fields |
||
59 | } |
||
60 |