InVisionApp / go-health

Library for enabling asynchronous health checks in your service
MIT License
750 stars 58 forks source link

Indentation for JSON in NewJSONHandlerFunc #76

Open antonjah opened 3 years ago

antonjah commented 3 years ago

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.