forked from devfeel/dotweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_yaml.go
41 lines (37 loc) · 1014 Bytes
/
config_yaml.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
41
package config
import (
"gopkg.in/yaml.v2"
)
// UnmarshalYaml decodes the first document found within the in byte slice
// and assigns decoded values into the out value.
// For example:
//
// type T struct {
// F int `yaml:"a,omitempty"`
// B int
// }
// var t T
// yaml.Unmarshal([]byte("a: 1\nb: 2"), &t)
func UnmarshalYaml(content []byte, v interface{}) error {
return yaml.Unmarshal(content, v)
}
// MarshalYaml Marshal serializes the value provided into a YAML document.
// For example:
//
// type T struct {
// F int "a,omitempty"
// B int
// }
// yaml.Marshal(&T{B: 2}) // Returns "b: 2\n"
// yaml.Marshal(&T{F: 1}} // Returns "a: 1\nb: 0\n"
func MarshalYaml(v interface{}) (out []byte, err error) {
return yaml.Marshal(v)
}
// MarshalYamlString returns the Ymal encoding string format of v.
func MarshalYamlString(v interface{}) (out string) {
marshal, err := yaml.Marshal(v)
if err != nil {
return ""
}
return string(marshal)
}