holiday-api/render.go

21 lines
442 B
Go

package main
import (
"github.com/gin-gonic/gin"
)
func render[T any](c *gin.Context, status int, response T) {
switch c.GetHeader("accept") {
case "application/xml":
fallthrough
case "text/xml":
c.Header("content-type", c.GetHeader("accept")+"; charset=utf-8")
c.XML(status, response)
case "application/json":
fallthrough
default:
c.Header("content-type", "application/json; charset=utf-8")
c.JSON(status, response)
}
}