mirror of
https://github.com/gin-gonic/gin.git
synced 2025-06-19 09:46:21 +08:00
Some work around bindings. it may do not compile
This commit is contained in:
34
binding/binding.go
Normal file
34
binding/binding.go
Normal file
@ -0,0 +1,34 @@
|
||||
package binding
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"io"
|
||||
)
|
||||
|
||||
type (
|
||||
Binding interface {
|
||||
Bind(io.Reader, interface{}) error
|
||||
}
|
||||
|
||||
// JSON binding
|
||||
jsonBinding struct{}
|
||||
|
||||
// JSON binding
|
||||
xmlBinding struct{}
|
||||
)
|
||||
|
||||
var (
|
||||
JSON = jsonBinding{}
|
||||
XML = xmlBinding{}
|
||||
)
|
||||
|
||||
func (_ jsonBinding) Bind(r io.Reader, obj interface{}) error {
|
||||
decoder := json.NewDecoder(r)
|
||||
return decoder.Decode(&obj)
|
||||
}
|
||||
|
||||
func (_ xmlBinding) Bind(r io.Reader, obj interface{}) error {
|
||||
decoder := xml.NewDecoder(r)
|
||||
return decoder.Decode(&obj)
|
||||
}
|
Reference in New Issue
Block a user