...
1
2
3
4
5
6
7 package render
8
9 import (
10 "net/http"
11
12 "github.com/ugorji/go/codec"
13 )
14
15
16
17 var (
18 _ Render = MsgPack{}
19 )
20
21
22 type MsgPack struct {
23 Data any
24 }
25
26 var msgpackContentType = []string{"application/msgpack; charset=utf-8"}
27
28
29 func (r MsgPack) WriteContentType(w http.ResponseWriter) {
30 writeContentType(w, msgpackContentType)
31 }
32
33
34 func (r MsgPack) Render(w http.ResponseWriter) error {
35 return WriteMsgPack(w, r.Data)
36 }
37
38
39 func WriteMsgPack(w http.ResponseWriter, obj any) error {
40 writeContentType(w, msgpackContentType)
41 var mh codec.MsgpackHandle
42 return codec.NewEncoder(w, &mh).Encode(obj)
43 }
44
View as plain text