gin/render/render.go

42 lines
1.1 KiB
Go
Raw Normal View History

2014-08-29 21:49:50 +04: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 19:41:56 +04:00
package render
import "net/http"
2022-04-04 11:28:49 +03:00
// Render interface is to be implemented by JSON, XML, HTML, YAML, AVRO and so on.
type Render interface {
// Render writes data with custom ContentType.
2015-06-04 06:25:21 +03:00
Render(http.ResponseWriter) error
// WriteContentType writes custom ContentType.
WriteContentType(w http.ResponseWriter)
}
2014-07-15 19:41:56 +04:00
var (
2015-05-18 16:45:24 +03:00
_ Render = JSON{}
_ Render = IndentedJSON{}
_ Render = SecureJSON{}
2018-04-26 06:52:19 +03:00
_ Render = JsonpJSON{}
2015-05-18 16:45:24 +03:00
_ Render = XML{}
_ Render = String{}
_ Render = Redirect{}
_ Render = Data{}
_ Render = HTML{}
_ HTMLRender = HTMLDebug{}
_ HTMLRender = HTMLProduction{}
2016-04-15 00:47:49 +03:00
_ Render = YAML{}
_ Render = Reader{}
_ Render = AsciiJSON{}
_ Render = ProtoBuf{}
2022-04-04 11:28:49 +03:00
_ Render = AVRO{}
2014-07-15 19:41:56 +04:00
)
func writeContentType(w http.ResponseWriter, value []string) {
header := w.Header()
if val := header["Content-Type"]; len(val) == 0 {
header["Content-Type"] = value
}
}