SaveFile saves object to file. suffix of filepath will be used as file type. currently, json and yaml is supported
(file string, data interface{})
| 71 | //SaveFile saves object to file. suffix of filepath will be |
| 72 | // used as file type. currently, json and yaml is supported |
| 73 | func 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 |