gin/render/common/common.go

25 lines
652 B
Go
Raw Normal View History

2019-04-17 17:10:21 +03:00
package common
import (
"net/http"
)
//WriteContentType set the content-type header
func WriteContentType(w http.ResponseWriter, value []string) {
header := w.Header()
if val := header["Content-Type"]; len(val) == 0 {
header["Content-Type"] = value
}
}
// 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)
}
//List hold the defined render (obj, options)
var List = map[string]func(interface{}, map[string]string) Render{}