Test: Changes are currently independent of the rest of this project. Tests can currently manually be run with "make test". CL is large, but poses no risk Change-Id: Ia77e073df077257cab96b7ca4e1d99a900d029b2
34 lines
614 B
Go
34 lines
614 B
Go
package filesystem
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
)
|
|
|
|
const fourSpaces = " "
|
|
const defaultReadPermissions = 0644
|
|
|
|
func WriteJsonSerializableToFile(jsonEntity interface{}, filename string) error {
|
|
serialized, err := json.MarshalIndent(jsonEntity, "", fourSpaces)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return ioutil.WriteFile(
|
|
filename,
|
|
serialized,
|
|
defaultReadPermissions,
|
|
)
|
|
}
|
|
|
|
func ReadFileAsJson(filename string, outputEntityAddress interface{}) error {
|
|
fileContents, err := ioutil.ReadFile(filename)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return json.Unmarshal(fileContents, outputEntityAddress)
|
|
}
|