Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to format JSON response with an indent. #56

Closed
wants to merge 1 commit into from

Conversation

hbchai
Copy link
Contributor

@hbchai hbchai commented Sep 15, 2015

This would support human-readable responses, when desired, by setting the runtime.ResponseIndent global. Just the non-streaming response can be indented for now.

@yugui
Copy link
Member

yugui commented Sep 15, 2015

Interesting. But can I consider this PR after #53? I guess this feature gets easier to implement without adding hacky flag once we complete #53.

@hbchai
Copy link
Contributor Author

hbchai commented Sep 15, 2015

Sounds reasonable. I think options are probably better in the long run, as long as they are easy to set.

@@ -11,6 +12,11 @@ import (
"golang.org/x/net/context"
)

var (
// The indent to use for JSON responses.
ResponseIndent = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally I see public variables in golang as constants, but there are exceptions - I would generally do something like:

var (
  responseIndent = ""
)

func SetResponseIndent(s string) {
  responseIndent = s
}

But just my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

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

@peter-edge, what would the benefit of having SetResponseIndent be?

Choose a reason for hiding this comment

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

@shurcooL the SetResponseIndent could easily do things like strip invalid indentation characters, particularly via a whitelist of simply [" ","\t"], for example. Getter/Setter pattern hides implementation details and can help protect invalid usage of exported variables in a package.

@yugui
Copy link
Member

yugui commented May 20, 2016

Now we can indent JSON outputs with JSONPb marshaler.

@yugui yugui closed this May 20, 2016
ithinker1991 pushed a commit to tronprotocol/grpc-gateway that referenced this pull request May 27, 2018
…ee_operation_limit

Feature/add free operation limit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants