2014-08-29 19:49:50 +02:00
|
|
|
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2014-07-15 17:41:56 +02:00
|
|
|
package render
|
|
|
|
|
2015-05-07 12:44:52 +02:00
|
|
|
import "net/http"
|
2015-03-08 17:50:58 +01:00
|
|
|
|
2018-09-15 10:23:32 +08:00
|
|
|
// Render interface is to be implemented by JSON, XML, HTML, YAML and so on.
|
2015-05-07 12:44:52 +02:00
|
|
|
type Render interface {
|
2018-09-15 10:23:32 +08:00
|
|
|
// Render writes data with custom ContentType.
|
2015-06-04 05:25:21 +02:00
|
|
|
Render(http.ResponseWriter) error
|
2018-09-15 10:23:32 +08:00
|
|
|
// WriteContentType writes custom ContentType.
|
2017-01-09 16:24:48 +01:00
|
|
|
WriteContentType(w http.ResponseWriter)
|
2015-05-07 12:44:52 +02:00
|
|
|
}
|
2014-07-15 17:41:56 +02:00
|
|
|
|
|
|
|
var (
|
2015-05-18 15:45:24 +02:00
|
|
|
_ Render = JSON{}
|
|
|
|
_ Render = IndentedJSON{}
|
2017-07-08 01:21:30 +08:00
|
|
|
_ Render = SecureJSON{}
|
2018-04-26 11:52:19 +08:00
|
|
|
_ Render = JsonpJSON{}
|
2015-05-18 15:45:24 +02:00
|
|
|
_ Render = XML{}
|
|
|
|
_ Render = String{}
|
|
|
|
_ Render = Redirect{}
|
|
|
|
_ Render = Data{}
|
|
|
|
_ Render = HTML{}
|
|
|
|
_ HTMLRender = HTMLDebug{}
|
|
|
|
_ HTMLRender = HTMLProduction{}
|
2016-04-14 23:47:49 +02:00
|
|
|
_ Render = YAML{}
|
2017-02-23 15:08:37 +01:00
|
|
|
_ Render = MsgPack{}
|
2018-05-12 05:00:42 +02:00
|
|
|
_ Render = Reader{}
|
2018-08-06 23:08:01 +08:00
|
|
|
_ Render = AsciiJSON{}
|
2018-08-19 10:45:56 +08:00
|
|
|
_ Render = ProtoBuf{}
|
2014-07-15 17:41:56 +02:00
|
|
|
)
|
2015-06-13 04:29:10 +02:00
|
|
|
|
|
|
|
func writeContentType(w http.ResponseWriter, value []string) {
|
|
|
|
header := w.Header()
|
|
|
|
if val := header["Content-Type"]; len(val) == 0 {
|
|
|
|
header["Content-Type"] = value
|
|
|
|
}
|
|
|
|
}
|