-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.go
37 lines (29 loc) · 832 Bytes
/
structs.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 swissknife
import (
"encoding/json"
"gopkg.in/yaml.v3"
)
// SaveStructToJSONFile save structure to JSON file
func SaveStructToJSONFile(i interface{}, filepath string) error {
jsonr, err := json.Marshal(i)
if err != nil {
return err
}
return SaveStringToFile(filepath, string(jsonr))
}
// SaveStructToJSONFileIndent save structure to JSON file
func SaveStructToJSONFileIndent(i interface{}, filepath string) error {
jsonr, err := json.MarshalIndent(i, "", " ")
if err != nil {
return err
}
return SaveStringToFile(filepath, string(jsonr))
}
// SaveStructToYamlFile save structure to YAML file (in plain text)
func SaveStructToYamlFile(i interface{}, filepath string) error {
dataEncoded, err := yaml.Marshal(i)
if err != nil {
return err
}
return SaveStringToFile(filepath, string(dataEncoded))
}