MessagePack
Content-Type: "application/msgpack"
MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves. https://msgpack.org
The Context.MsgPack(v) is the method which sends MessagePack responses to the client. It accepts any Go value. As always, if it's a struct value, the fields should be exported.
1
type Data struct {
2
Message string `msgpack:"message"`
3
}
4
5
func handler(ctx iris.Context) {
6
response := Data{Message: "a message"}
7
ctx.MsgPack(response)
8
}
Copied!
Result
1
\x81\xa7message\xa9a message
Copied!
Last modified 1yr ago
Export as PDF
Copy link