mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-25 09:50:31 +00:00
4df9c8d6a5
* github.com/russross/meddler v1.0.0 -> v1.0.1 * github.com/gin-gonic/gin v1.6.3 -> v1.7.4 * github.com/go-sql-driver/mysql v1.5.0 -> v1.6.0 * github.com/sirupsen/logrus v1.6.0 -> v1.8.1 * github.com/rs/zerolog v1.18.0 -> v1.25.0
38 lines
814 B
Go
38 lines
814 B
Go
// 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 binding
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/ugorji/go/codec"
|
|
)
|
|
|
|
type msgpackBinding struct{}
|
|
|
|
func (msgpackBinding) Name() string {
|
|
return "msgpack"
|
|
}
|
|
|
|
func (msgpackBinding) Bind(req *http.Request, obj interface{}) error {
|
|
return decodeMsgPack(req.Body, obj)
|
|
}
|
|
|
|
func (msgpackBinding) BindBody(body []byte, obj interface{}) error {
|
|
return decodeMsgPack(bytes.NewReader(body), obj)
|
|
}
|
|
|
|
func decodeMsgPack(r io.Reader, obj interface{}) error {
|
|
cdc := new(codec.MsgpackHandle)
|
|
if err := codec.NewDecoder(r, cdc).Decode(&obj); err != nil {
|
|
return err
|
|
}
|
|
return validate(obj)
|
|
}
|