report errors via JSON

This reflects the latest SPEC draft.
This commit is contained in:
Eugene Yakubovich
2015-04-29 17:52:41 -07:00
parent ed97604e74
commit a4896a9401
3 changed files with 32 additions and 9 deletions

View File

@ -125,9 +125,18 @@ func ConfigureIface(ifName string, res *Result) error {
return nil
}
// PrintResult writes out prettified Result to stdout
// PrintResult writes out prettified Result JSON to stdout
func PrintResult(res *Result) error {
data, err := json.MarshalIndent(res, "", " ")
return prettyPrint(res)
}
// PrintError writes out prettified Error JSON to stdout
func PrintError(err *Error) error {
return prettyPrint(err)
}
func prettyPrint(obj interface{}) error {
data, err := json.MarshalIndent(obj, "", " ")
if err != nil {
return err
}