woodpecker/vendor/github.com/gin-gonic/gin/render/msgpack.go
6543 4df9c8d6a5
Update Dependencies (#349)
* github.com/russross/meddler v1.0.0 -> v1.0.1
* github.com/gin-gonic/gin v1.6.3 -> v1.7.4
* github.com/go-sql-driver/mysql v1.5.0 -> v1.6.0
* github.com/sirupsen/logrus v1.6.0 -> v1.8.1
* github.com/rs/zerolog v1.18.0 -> v1.25.0
2021-09-24 18:39:57 +02:00

43 lines
1.1 KiB
Go

// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
//go:build !nomsgpack
// +build !nomsgpack
package render
import (
"net/http"
"github.com/ugorji/go/codec"
)
var (
_ Render = MsgPack{}
)
// MsgPack contains the given interface object.
type MsgPack struct {
Data interface{}
}
var msgpackContentType = []string{"application/msgpack; charset=utf-8"}
// WriteContentType (MsgPack) writes MsgPack ContentType.
func (r MsgPack) WriteContentType(w http.ResponseWriter) {
writeContentType(w, msgpackContentType)
}
// Render (MsgPack) encodes the given interface object and writes data with custom ContentType.
func (r MsgPack) Render(w http.ResponseWriter) error {
return WriteMsgPack(w, r.Data)
}
// WriteMsgPack writes MsgPack ContentType and encodes the given interface object.
func WriteMsgPack(w http.ResponseWriter, obj interface{}) error {
writeContentType(w, msgpackContentType)
var mh codec.MsgpackHandle
return codec.NewEncoder(w, &mh).Encode(obj)
}