9957: Refactor keep-web to load config from a file, with legacy support for command...
[arvados.git] / sdk / go / config / load.go
1 package config
2
3 import (
4         "encoding/json"
5         "fmt"
6         "io/ioutil"
7 )
8
9 // LoadFile loads configuration from the file given by configPath and
10 // decodes it into cfg.
11 //
12 // Currently, only JSON is supported. Support for YAML is anticipated.
13 func LoadFile(cfg interface{}, configPath string) error {
14         buf, err := ioutil.ReadFile(configPath)
15         if err != nil {
16                 return err
17         }
18         err = json.Unmarshal(buf, cfg)
19         if err != nil {
20                 return fmt.Errorf("Error decoding config %q: %v", configPath, err)
21         }
22         return nil
23 }