2018-08-20 10:15:31 +03:00
|
|
|
// Copyright 2018 Gin Core Team. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build go1.7
|
|
|
|
|
|
|
|
package render
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-08-30 14:04:03 +03:00
|
|
|
"github.com/gin-gonic/gin/internal/json"
|
2018-08-20 10:15:31 +03:00
|
|
|
)
|
|
|
|
|
2018-09-15 05:23:32 +03:00
|
|
|
// PureJSON contains the given interface object.
|
2018-08-20 10:15:31 +03:00
|
|
|
type PureJSON struct {
|
|
|
|
Data interface{}
|
|
|
|
}
|
|
|
|
|
2018-09-15 05:23:32 +03:00
|
|
|
// Render (PureJSON) writes custom ContentType and encodes the given interface object.
|
2018-08-20 10:15:31 +03:00
|
|
|
func (r PureJSON) Render(w http.ResponseWriter) error {
|
|
|
|
r.WriteContentType(w)
|
|
|
|
encoder := json.NewEncoder(w)
|
|
|
|
encoder.SetEscapeHTML(false)
|
|
|
|
return encoder.Encode(r.Data)
|
|
|
|
}
|
|
|
|
|
2018-09-15 05:23:32 +03:00
|
|
|
// WriteContentType (PureJSON) writes custom ContentType.
|
2018-08-20 10:15:31 +03:00
|
|
|
func (r PureJSON) WriteContentType(w http.ResponseWriter) {
|
|
|
|
writeContentType(w, jsonContentType)
|
|
|
|
}
|