OSDN Git Service

feat(warder): add warder backbone (#181)
[bytom/vapor.git] / vendor / github.com / gin-gonic / gin / render / msgpack.go
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 package render
6
7 import (
8         "net/http"
9
10         "github.com/ugorji/go/codec"
11 )
12
13 type MsgPack struct {
14         Data interface{}
15 }
16
17 var msgpackContentType = []string{"application/msgpack; charset=utf-8"}
18
19 func (r MsgPack) WriteContentType(w http.ResponseWriter) {
20         writeContentType(w, msgpackContentType)
21 }
22
23 func (r MsgPack) Render(w http.ResponseWriter) error {
24         return WriteMsgPack(w, r.Data)
25 }
26
27 func 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 }