podman
1// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
3// license that can be found in the LICENSE file.
4
5//go:build !nomsgpack
6
7package render8
9import (10"net/http"11
12"github.com/ugorji/go/codec"13)
14
15// Check interface implemented here to support go build tag nomsgpack.
16// See: https://github.com/gin-gonic/gin/pull/1852/
17var (18_ Render = MsgPack{}19)
20
21// MsgPack contains the given interface object.
22type MsgPack struct {23Data any
24}
25
26var msgpackContentType = []string{"application/msgpack; charset=utf-8"}27
28// WriteContentType (MsgPack) writes MsgPack ContentType.
29func (r MsgPack) WriteContentType(w http.ResponseWriter) {30writeContentType(w, msgpackContentType)31}
32
33// Render (MsgPack) encodes the given interface object and writes data with custom ContentType.
34func (r MsgPack) Render(w http.ResponseWriter) error {35return WriteMsgPack(w, r.Data)36}
37
38// WriteMsgPack writes MsgPack ContentType and encodes the given interface object.
39func WriteMsgPack(w http.ResponseWriter, obj any) error {40writeContentType(w, msgpackContentType)41var mh codec.MsgpackHandle42return codec.NewEncoder(w, &mh).Encode(obj)43}
44