Debugging function to pretty-print results.
diff --git a/results.go b/results.go
index f60bc76..19557fb 100644
--- a/results.go
+++ b/results.go
@@ -1,6 +1,9 @@
package gophercloud
-import "net/http"
+import (
+ "encoding/json"
+ "net/http"
+)
// Result acts as a base struct that other results can embed.
type Result struct {
@@ -16,6 +19,15 @@
Err error
}
+// PrettyPrintJSON creates a string containing the full response body as pretty-printed JSON.
+func (r Result) PrettyPrintJSON() string {
+ pretty, err := json.MarshalIndent(r.Body, "", " ")
+ if err != nil {
+ panic(err.Error())
+ }
+ return string(pretty)
+}
+
// RFC3339Milli describes a time format used by API responses.
const RFC3339Milli = "2006-01-02T15:04:05.999999Z"