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

Indentation for JSON in NewJSONHandlerFunc #76

Open
antonjah opened this issue May 20, 2021 · 0 comments
Open

Indentation for JSON in NewJSONHandlerFunc #76

antonjah opened this issue May 20, 2021 · 0 comments

Comments

@antonjah
Copy link

antonjah commented May 20, 2021

When using go-health together with gin-gonic I'm finding it hard to format the JSON output from NewJSONHandlerFunc().
Would it be possible to update the signature of NewJSONHandlerFunc() to include some kind of config? I don't really know what approach that would be the best, but some pseudo examples:

func NewJSONHandlerFunc(h health.IHealth, custom map[string]interface{}, formatConfig *health.FomatConfig) http.HandlerFunc {
    ...

    encoder := json.NewEncoder(...)
    if formatConfig != nil {
        encoder.SetIndent(formatConfig.Prefix, formatConfig.Indent)
    }
    json.Encode(...)
}

Or something simple like:

func NewJSONHandlerFunc(h health.IHealth, custom map[string]interface{}, prefix, indent string) http.HandlerFunc {
    ...
    data, err := json.MarshalIndent(fullBody.data, prefix, indent)
}

Like I said, I don't know the best (go) approach for this. And if this is possible somehow already I would be happy for all the information I can get.

Thanks for a very nice project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant