2022-05-28 05:42:28 +03:00
|
|
|
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
|
2014-08-29 21:49:50 +04:00
|
|
|
// Use of this source code is governed by a MIT style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2014-07-15 19:41:56 +04:00
|
|
|
package render
|
|
|
|
|
2015-05-07 13:44:52 +03:00
|
|
|
import "net/http"
|
2015-03-08 19:50:58 +03:00
|
|
|
|
2018-09-15 05:23:32 +03:00
|
|
|
// Render interface is to be implemented by JSON, XML, HTML, YAML and so on.
|
2015-05-07 13:44:52 +03:00
|
|
|
type Render interface {
|
2018-09-15 05:23:32 +03:00
|
|
|
// Render writes data with custom ContentType.
|
2015-06-04 06:25:21 +03:00
|
|
|
Render(http.ResponseWriter) error
|
2018-09-15 05:23:32 +03:00
|
|
|
// WriteContentType writes custom ContentType.
|
2017-01-09 18:24:48 +03:00
|
|
|
WriteContentType(w http.ResponseWriter)
|
2015-05-07 13:44:52 +03:00
|
|
|
}
|
2014-07-15 19:41:56 +04:00
|
|
|
|
|
|
|
var (
|
2024-03-06 17:27:21 +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)
|
2014-07-15 19:41:56 +04:00
|
|
|
)
|
2015-06-13 05:29:10 +03:00
|
|
|
|
|
|
|
func writeContentType(w http.ResponseWriter, value []string) {
|
|
|
|
header := w.Header()
|
|
|
|
if val := header["Content-Type"]; len(val) == 0 {
|
|
|
|
header["Content-Type"] = value
|
|
|
|
}
|
|
|
|
}
|