From 6bdba534b5441ff5592315678bdc7684a2dd1352 Mon Sep 17 00:00:00 2001 From: Pratik Mallya Date: Wed, 23 Sep 2015 18:12:11 -0500 Subject: [PATCH] Add PrettyPrintJSON method for gophercloud.Link structure This helper method is useful when the contents need to be displayed. --- results.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/results.go b/results.go index 27fd1b60..95f58599 100644 --- a/results.go +++ b/results.go @@ -129,6 +129,16 @@ type Link struct { Rel string `mapstructure:"rel"` } +// PrettyPrintJSON creates a string containing the links as +// pretty-printed JSON. It is useful for displaying the results. +func (link Link) PrettyPrintJSON() string { + pretty, err := json.MarshalIndent(link, "", " ") + if err != nil { + panic(err.Error()) + } + return string(pretty) +} + /* ExtractNextURL is an internal function useful for packages of collection resources that are paginated in a certain way.