forked from sahib/brig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
defaults.go
37 lines (28 loc) · 931 Bytes
/
defaults.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
package defaults
import (
"os"
e "github.com/pkg/errors"
"github.com/sahib/config"
)
// CurrentVersion is the current version of brig's config
const CurrentVersion = 0
// Defaults is the default validation for brig
var Defaults = DefaultsV0
// OpenMigratedConfig takes the config.yml at path and loads it.
// If required, it also migrates the config structure to the newest
// version - brig can always rely on the latest config keys to be present.
func OpenMigratedConfig(path string) (*config.Config, error) {
fd, err := os.Open(path)
if err != nil {
return nil, e.Wrap(err, "failed to open config")
}
defer fd.Close()
// NOTE: Add here any migrations with mgr.Add if needed.
mgr := config.NewMigrater(CurrentVersion, config.StrictnessPanic)
mgr.Add(0, nil, DefaultsV0)
cfg, err := mgr.Migrate(config.NewYamlDecoder(fd))
if err != nil {
return nil, e.Wrap(err, "failed to migrate")
}
return cfg, nil
}