forked from gin-gonic/gin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for MessagePack binding and rendering
Added deps to vendor.json and fixed rendering bug Fixed vendoring bug
- Loading branch information
Harindu Perera
committed
Feb 17, 2017
1 parent
8632480
commit 2f20804
Showing
7 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2014 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. | ||
|
||
package binding | ||
|
||
import ( | ||
"github.com/ugorji/go/codec" | ||
|
||
"net/http" | ||
) | ||
|
||
type msgpackBinding struct{} | ||
|
||
func (msgpackBinding) Name() string { | ||
return "msgpack" | ||
} | ||
|
||
func (msgpackBinding) Bind(req *http.Request, obj interface{}) error { | ||
|
||
if err := codec.NewDecoder(req.Body, new(codec.MsgpackHandle)).Decode(&obj); err != nil { | ||
//var decoder *codec.Decoder = codec.NewDecoder(req.Body, &codec.MsgpackHandle) | ||
//if err := decoder.Decode(&obj); err != nil { | ||
return err | ||
} | ||
return validate(obj) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2014 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. | ||
|
||
package render | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/ugorji/go/codec" | ||
) | ||
|
||
type MsgPack struct { | ||
Data interface{} | ||
} | ||
|
||
var msgpackContentType = []string{"application/msgpack; charset=utf-8"} | ||
|
||
func (r MsgPack) WriteContentType(w http.ResponseWriter) { | ||
writeContentType(w, msgpackContentType) | ||
} | ||
|
||
func (r MsgPack) Render(w http.ResponseWriter) error { | ||
return WriteMsgPack(w, r.Data) | ||
} | ||
|
||
func WriteMsgPack(w http.ResponseWriter, obj interface{}) error { | ||
writeContentType(w, msgpackContentType) | ||
var h codec.Handle = new(codec.MsgpackHandle) | ||
return codec.NewEncoder(w, h).Encode(obj) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters