holiday-api/render.go

21 lines
442 B
Go
Raw Normal View History

2023-06-16 07:42:50 +00:00
package main
import (
2023-06-23 17:31:02 +00:00
"github.com/gin-gonic/gin"
2023-06-16 07:42:50 +00:00
)
2023-06-23 17:31:02 +00:00
func render[T any](c *gin.Context, status int, response T) {
switch c.GetHeader("accept") {
2023-06-20 14:10:46 +00:00
case "application/xml":
fallthrough
case "text/xml":
2023-06-23 17:31:02 +00:00
c.Header("content-type", c.GetHeader("accept")+"; charset=utf-8")
c.XML(status, response)
2023-06-20 14:10:46 +00:00
case "application/json":
fallthrough
default:
2023-06-23 17:31:02 +00:00
c.Header("content-type", "application/json; charset=utf-8")
c.JSON(status, response)
2023-06-16 07:42:50 +00:00
}
}