json_17.go 578 B

12345678910111213141516171819202122232425262728
  1. // Copyright 2018 Gin Core Team. All rights reserved.
  2. // Use of this source code is governed by a MIT style
  3. // license that can be found in the LICENSE file.
  4. // +build go1.7
  5. package render
  6. import (
  7. "net/http"
  8. "github.com/gin-gonic/gin/internal/json"
  9. )
  10. type PureJSON struct {
  11. Data interface{}
  12. }
  13. func (r PureJSON) Render(w http.ResponseWriter) error {
  14. r.WriteContentType(w)
  15. encoder := json.NewEncoder(w)
  16. encoder.SetEscapeHTML(false)
  17. return encoder.Encode(r.Data)
  18. }
  19. func (r PureJSON) WriteContentType(w http.ResponseWriter) {
  20. writeContentType(w, jsonContentType)
  21. }