MCPcopy Create free account
hub / github.com/cloudwan/gohan / SaveFile

Function SaveFile

util/util.go:73–86  ·  view source on GitHub ↗

SaveFile saves object to file. suffix of filepath will be used as file type. currently, json and yaml is supported

(file string, data interface{})

Source from the content-addressed store, hash-verified

71//SaveFile saves object to file. suffix of filepath will be
72// used as file type. currently, json and yaml is supported
73func SaveFile(file string, data interface{}) error {
74 var bytes []byte
75 var err error
76 if strings.HasSuffix(file, ".json") {
77 bytes, err = json.MarshalIndent(data, "", " ")
78 } else if strings.HasSuffix(file, ".yaml") || strings.HasSuffix(file, ".yml") {
79 bytes, err = yaml.Marshal(data)
80
81 }
82 if err != nil {
83 return err
84 }
85 return ioutil.WriteFile(file, bytes, os.ModePerm)
86}
87
88//LoadMap loads map object from file. suffix of filepath will be
89// used as file type. currently, json and yaml is supported

Callers 1

testFileUtilFunction · 0.85

Calls

no outgoing calls

Tested by 1

testFileUtilFunction · 0.68