Skip to content
Myr

msgpack.go

This file

Path

render/msgpack.go

43 lines · 1.1 KiB · Go

Last changed by

chore: support min go version 1.18 (#3511)thinkeroubefore adoption1e1f0b1

History of this file

Take it

The walk stopped after 200 commits: lines older than a550c56 point at it.

chore: update go.mod and remove space from copyright (#3158)thinkeroubefore adoption4b68a5f

line 1why, one step back
1// Copyright 2017 Manu Martinez-Almeida. All rights reserved.

chore: Add go1.17 for testing (#2828)Bo-Yi Wubefore adoptiona550c56

lines 2–22why, one step back
2// Use of this source code is governed by a MIT style
3// license that can be found in the LICENSE file.45//go:build !nomsgpack67package render89import (10 "net/http"1112 "github.com/ugorji/go/codec"13)1415// Check interface implemented here to support go build tag nomsgpack.16// See: https://github.com/gin-gonic/gin/pull/1852/17var (18 _ Render = MsgPack{}19)2021// MsgPack contains the given interface object.22type MsgPack struct {

test support go1.18 (#2990)thinkeroubefore adoption2bde107

line 23why, one step back
23 Data any

chore: Add go1.17 for testing (#2828)Bo-Yi Wubefore adoptiona550c56

lines 24–38why, one step back
24}
2526var msgpackContentType = []string{"application/msgpack; charset=utf-8"}2728// WriteContentType (MsgPack) writes MsgPack ContentType.29func (r MsgPack) WriteContentType(w http.ResponseWriter) {30 writeContentType(w, msgpackContentType)31}3233// Render (MsgPack) encodes the given interface object and writes data with custom ContentType.34func (r MsgPack) Render(w http.ResponseWriter) error {35 return WriteMsgPack(w, r.Data)36}3738// WriteMsgPack writes MsgPack ContentType and encodes the given interface object.

test support go1.18 (#2990)thinkeroubefore adoption2bde107

line 39why, one step back
39func WriteMsgPack(w http.ResponseWriter, obj any) error {

chore: Add go1.17 for testing (#2828)Bo-Yi Wubefore adoptiona550c56

lines 40–43why, one step back
40 writeContentType(w, msgpackContentType)
41 var mh codec.MsgpackHandle42 return codec.NewEncoder(w, &mh).Encode(obj)43}