/
githubmirror
/
gin
Обзор
Документация
Войти
/
githubmirror
/
gin
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v1.7.1
render/msgpack.go
42 строки
1 KB
thinkerou
build: convert to go:build directives (#2664)
27 мар 2021, 04:09
Не верифицирован
27 мар 2021, 04:09
ed6f85c
Код
Авторство
О чём код?
// Copyright 2017 Manu Martinez-Almeida. All rights reserved. // Use of this source code is governed by a MIT style // license that can be found in the LICENSE file. //go:build !nomsgpack // +build !nomsgpack package render import ( "net/http" "github.com/ugorji/go/codec" ) var ( _ Render = MsgPack{} ) // MsgPack contains the given interface object. type MsgPack struct { Data interface{} } var msgpackContentType = []string{"application/msgpack; charset=utf-8"} // WriteContentType (MsgPack) writes MsgPack ContentType. func (r MsgPack) WriteContentType(w http.ResponseWriter) { writeContentType(w, msgpackContentType) } // Render (MsgPack) encodes the given interface object and writes data with custom ContentType. func (r MsgPack) Render(w http.ResponseWriter) error { return WriteMsgPack(w, r.Data) } // WriteMsgPack writes MsgPack ContentType and encodes the given interface object. func WriteMsgPack(w http.ResponseWriter, obj interface{}) error { writeContentType(w, msgpackContentType) var mh codec.MsgpackHandle return codec.NewEncoder(w, &mh).Encode(obj) }