28 lines
450 B
Go
28 lines
450 B
Go
package utio
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
)
|
|
|
|
// JSONer describes a JSON encoder/decoder.
|
|
type JSONer interface {
|
|
Encoder
|
|
Decoder
|
|
}
|
|
|
|
// JSON creates a JSON encoder/decoder for v.
|
|
func JSON(v interface{}) JSONer {
|
|
return &jsoner{v}
|
|
}
|
|
|
|
type jsoner struct{ v interface{} }
|
|
|
|
func (j *jsoner) Decode(r io.Reader) error {
|
|
return json.NewDecoder(r).Decode(j.v)
|
|
}
|
|
|
|
func (j *jsoner) Encode(w io.Writer) error {
|
|
return json.NewEncoder(w).Encode(j.v)
|
|
}
|