Exemplo n.º 1
0
func render(ctx *macaron.Context, output []byte, err error, contentType string) {
	if err != nil {
		ctx.Error(500, err.Error()+"\n"+string(output))
		return
	}
	if contentType == "" {
		contentType = "text"
	}
	switch contentType {
	case "html":
		ctx.Header().Set("Content-Type", "text/html")
	case "json":
		ctx.Header().Set("Content-Type", "application/json; charset=UTF-8")
	case "text":
		ctx.Header().Set("Content-Type", "text/plain")
	default:
		ctx.Header().Set("Content-Type", contentType)
	}
	ctx.Write(output)
}