projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'main' from arvados-workbench2.git
[arvados.git]
/
sdk
/
go
/
config
/
load.go
diff --git
a/sdk/go/config/load.go
b/sdk/go/config/load.go
index 143be8be23eedf319de1a8bf90ec3428dc2c944a..cab09c74e883c3dafabd22d11037e6e1a3dcc3ab 100644
(file)
--- a/
sdk/go/config/load.go
+++ b/
sdk/go/config/load.go
@@
-1,23
+1,33
@@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+
package config
import (
package config
import (
- "encoding/json"
"fmt"
"io/ioutil"
"fmt"
"io/ioutil"
+
+ "github.com/ghodss/yaml"
)
// LoadFile loads configuration from the file given by configPath and
// decodes it into cfg.
//
)
// LoadFile loads configuration from the file given by configPath and
// decodes it into cfg.
//
-//
Currently, only JSON is supported. Support for YAML is anticipa
ted.
+//
YAML and JSON formats are suppor
ted.
func LoadFile(cfg interface{}, configPath string) error {
buf, err := ioutil.ReadFile(configPath)
if err != nil {
return err
}
func LoadFile(cfg interface{}, configPath string) error {
buf, err := ioutil.ReadFile(configPath)
if err != nil {
return err
}
- err =
json
.Unmarshal(buf, cfg)
+ err =
yaml
.Unmarshal(buf, cfg)
if err != nil {
return fmt.Errorf("Error decoding config %q: %v", configPath, err)
}
return nil
}
if err != nil {
return fmt.Errorf("Error decoding config %q: %v", configPath, err)
}
return nil
}
+
+// Dump returns a YAML representation of cfg.
+func Dump(cfg interface{}) ([]byte, error) {
+ return yaml.Marshal(cfg)
+}