msgpack.go
This file
Path
render/msgpack.go
35 lines · 1015 bytes · Go
Last changed by
chore: add some annotations (#1544)田欧before adoptiond510595
History of this fileTake it
1// Copyright 2017 Manu Martinez-Almeida. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45package render67import (8 "net/http"910 "github.com/ugorji/go/codec"11)1213// MsgPack contains the given interface object.14type MsgPack struct {15 Data interface{}16}1718var msgpackContentType = []string{"application/msgpack; charset=utf-8"}1920// WriteContentType (MsgPack) writes MsgPack ContentType.21func (r MsgPack) WriteContentType(w http.ResponseWriter) {22 writeContentType(w, msgpackContentType)23}2425// Render (MsgPack) encodes the given interface object and writes data with custom ContentType.26func (r MsgPack) Render(w http.ResponseWriter) error {27 return WriteMsgPack(w, r.Data)28}2930// WriteMsgPack writes MsgPack ContentType and encodes the given interface object.31func WriteMsgPack(w http.ResponseWriter, obj interface{}) error {32 writeContentType(w, msgpackContentType)33 var mh codec.MsgpackHandle34 return codec.NewEncoder(w, &mh).Encode(obj)35}