Some work around bindings. it may do not compile

This commit is contained in:
Manu Mtz-Almeida
2014-07-03 19:19:06 +02:00
parent b8053b284d
commit 1aa3216303
3 changed files with 72 additions and 9 deletions

34
binding/binding.go Normal file
View 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)
}