Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions results.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use-case for this? The gophercloud.Links should be formatted if they are in the result and gophercloud.Result.PrettyPrintJSON is called. When would you need to format the links separately?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrperritt that will format the entire result as JSON; but there are cases where we don't want all the result as JSON, only the links. e.g. https://github.com/rackspace/rack/pull/346/files#diff-89ed2b55dee1ba0cb9742aba85a8f6deR58

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.
Expand Down