report errors via JSON
This reflects the latest SPEC draft.
This commit is contained in:
@ -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
|
||||
}
|
||||
|
@ -48,6 +48,12 @@ type Route struct {
|
||||
GW net.IP
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
Code uint `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Details string `json:"details,omitempty"`
|
||||
}
|
||||
|
||||
// net.IPNet is not JSON (un)marshallable so this duality is needed
|
||||
// for our custom ip.IPNet type
|
||||
|
||||
|
Reference in New Issue
Block a user