8784: Fix test for latest firefox.
[arvados.git] / sdk / go / config / load.go
1 package config
2
3 import (
4         "fmt"
5         "io/ioutil"
6
7         "github.com/ghodss/yaml"
8 )
9
10 // LoadFile loads configuration from the file given by configPath and
11 // decodes it into cfg.
12 //
13 // YAML and JSON formats are supported.
14 func LoadFile(cfg interface{}, configPath string) error {
15         buf, err := ioutil.ReadFile(configPath)
16         if err != nil {
17                 return err
18         }
19         err = yaml.Unmarshal(buf, cfg)
20         if err != nil {
21                 return fmt.Errorf("Error decoding config %q: %v", configPath, err)
22         }
23         return nil
24 }
25
26 // Dump returns a YAML representation of cfg.
27 func Dump(cfg interface{}) ([]byte, error) {
28         return yaml.Marshal(cfg)
29 }