-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
config.go
40 lines (31 loc) · 854 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"bytes"
"gopkg.in/yaml.v2"
)
type OldConfig struct {
Allowlist []string `yaml:"whitelist"`
Denylist []string `yaml:"blacklist"`
Exceptions []string `yaml:"exceptions"`
}
type Config struct {
Allowlist []string `yaml:"allowlist"`
Denylist []string `yaml:"denylist"`
Exceptions []string `yaml:"exceptions"`
}
func ReadConfig(config []byte) (*Config, error) {
t := Config{}
old := OldConfig{}
// Parse new format
if err := yaml.NewDecoder(bytes.NewReader(config)).Decode(&t); err != nil {
return nil, err
}
// Parse old format
if err := yaml.NewDecoder(bytes.NewReader(config)).Decode(&old); err != nil {
return nil, err
}
t.Allowlist = append(t.Allowlist, old.Allowlist...)
t.Denylist = append(t.Denylist, old.Denylist...)
t.Exceptions = append(t.Exceptions, old.Exceptions...)
return &t, nil
}