2022-09-28 20:30:40 +03:00
|
|
|
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
|
2021-08-12 22:03:24 +03:00
|
|
|
// Use of this source code is governed by a MIT style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package render
|
|
|
|
|
|
|
|
import "net/http"
|
|
|
|
|
|
|
|
// Render interface is to be implemented by JSON, XML, HTML, YAML and so on.
|
|
|
|
type Render interface {
|
|
|
|
// Render writes data with custom ContentType.
|
|
|
|
Render(http.ResponseWriter) error
|
|
|
|
// WriteContentType writes custom ContentType.
|
|
|
|
WriteContentType(w http.ResponseWriter)
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2024-05-21 16:17:22 +03:00
|
|
|
_ Render = (*JSON)(nil)
|
|
|
|
_ Render = (*IndentedJSON)(nil)
|
|
|
|
_ Render = (*SecureJSON)(nil)
|
|
|
|
_ Render = (*JsonpJSON)(nil)
|
|
|
|
_ Render = (*XML)(nil)
|
|
|
|
_ Render = (*String)(nil)
|
|
|
|
_ Render = (*Redirect)(nil)
|
|
|
|
_ Render = (*Data)(nil)
|
|
|
|
_ Render = (*HTML)(nil)
|
|
|
|
_ HTMLRender = (*HTMLDebug)(nil)
|
|
|
|
_ HTMLRender = (*HTMLProduction)(nil)
|
|
|
|
_ Render = (*YAML)(nil)
|
|
|
|
_ Render = (*Reader)(nil)
|
|
|
|
_ Render = (*AsciiJSON)(nil)
|
|
|
|
_ Render = (*ProtoBuf)(nil)
|
|
|
|
_ Render = (*TOML)(nil)
|
2021-08-12 22:03:24 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func writeContentType(w http.ResponseWriter, value []string) {
|
|
|
|
header := w.Header()
|
|
|
|
if val := header["Content-Type"]; len(val) == 0 {
|
|
|
|
header["Content-Type"] = value
|
|
|
|
}
|
|
|
|
}
|