• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package filesystem
2
3import (
4	"encoding/json"
5	"io/ioutil"
6)
7
8const fourSpaces = "    "
9const defaultReadPermissions = 0644
10
11func WriteJsonSerializableToFile(jsonEntity interface{}, filename string) error {
12	serialized, err := json.MarshalIndent(jsonEntity, "", fourSpaces)
13
14	if err != nil {
15		return err
16	}
17
18	return ioutil.WriteFile(
19		filename,
20		serialized,
21		defaultReadPermissions,
22	)
23}
24
25func ReadFileAsJson(filename string, outputEntityAddress interface{}) error {
26	fileContents, err := ioutil.ReadFile(filename)
27
28	if err != nil {
29		return err
30	}
31
32	return json.Unmarshal(fileContents, outputEntityAddress)
33}
34