Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
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 |
// +build !nomsgpack
|
|
6 |
|
|
7 |
package render |
|
8 |
|
|
9 |
import ( |
|
10 |
"net/http"
|
|
11 |
|
|
12 |
"github.com/ugorji/go/codec"
|
|
13 |
)
|
|
14 |
|
|
15 |
var ( |
|
16 |
_ Render = MsgPack{} |
|
17 |
)
|
|
18 |
|
|
19 |
// MsgPack contains the given interface object.
|
|
20 |
type MsgPack struct { |
|
21 |
Data interface{} |
|
22 |
}
|
|
23 |
|
|
24 |
var msgpackContentType = []string{"application/msgpack; charset=utf-8"} |
|
25 |
|
|
26 |
// WriteContentType (MsgPack) writes MsgPack ContentType.
|
|
27 |
func (r MsgPack) WriteContentType(w http.ResponseWriter) { |
|
28 | 6 |
writeContentType(w, msgpackContentType) |
29 |
}
|
|
30 |
|
|
31 |
// Render (MsgPack) encodes the given interface object and writes data with custom ContentType.
|
|
32 |
func (r MsgPack) Render(w http.ResponseWriter) error { |
|
33 | 6 |
return WriteMsgPack(w, r.Data) |
34 |
}
|
|
35 |
|
|
36 |
// WriteMsgPack writes MsgPack ContentType and encodes the given interface object.
|
|
37 |
func WriteMsgPack(w http.ResponseWriter, obj interface{}) error { |
|
38 | 6 |
writeContentType(w, msgpackContentType) |
39 | 6 |
var mh codec.MsgpackHandle |
40 | 6 |
return codec.NewEncoder(w, &mh).Encode(obj) |
41 |
}
|
Read our documentation on viewing source code .