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
5package render
6
7import (
8	"net/http"
9
10	"github.com/ugorji/go/codec"
11)
12
13type MsgPack struct {
14	Data interface{}
15}
16
17var msgpackContentType = []string{"application/msgpack; charset=utf-8"}
18
19func (r MsgPack) WriteContentType(w http.ResponseWriter) {
20	writeContentType(w, msgpackContentType)
21}
22
23func (r MsgPack) Render(w http.ResponseWriter) error {
24	return WriteMsgPack(w, r.Data)
25}
26
27func WriteMsgPack(w http.ResponseWriter, obj interface{}) error {
28	writeContentType(w, msgpackContentType)
29	var h codec.Handle = new(codec.MsgpackHandle)
30	return codec.NewEncoder(w, h).Encode(obj)
31}
32