Skip to content

Commit

Permalink
Returned public WriteJSON method
Browse files Browse the repository at this point in the history
  • Loading branch information
eeonevision committed Nov 27, 2019
1 parent ea0b535 commit 5381382
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions render/json.go
Expand Up @@ -63,6 +63,14 @@ func (r JSON) WriteContentType(w http.ResponseWriter) {
writeContentType(w, jsonContentType)
}

// WriteJSON marshals the given interface object and writes it with custom ContentType.
func WriteJSON(w http.ResponseWriter, obj interface{}) error {
writeContentType(w, jsonContentType)
encoder := json.NewEncoder(w)
err := encoder.Encode(&obj)
return err
}

// Render (IndentedJSON) marshals the given interface object and writes it with custom ContentType.
func (r IndentedJSON) Render(w http.ResponseWriter) error {
r.WriteContentType(w)
Expand Down

0 comments on commit 5381382

Please sign in to comment.