Use WriteJSON and ReadJSON on Conn struct.

This commit is contained in:
Craig Jackson 2013-10-26 01:13:32 -07:00 committed by Gary Burd
parent 1627eef2a3
commit 8e0dcebbf0
2 changed files with 4 additions and 4 deletions

View File

@ -12,7 +12,7 @@ import (
//
// See the documentation for encoding/json Marshal for details about the
// conversion of Go values to JSON.
func WriteJSON(c *Conn, v interface{}) error {
func (c *Conn) WriteJSON(v interface{}) error {
w, err := c.NextWriter(TextMessage)
if err != nil {
return err
@ -30,7 +30,7 @@ func WriteJSON(c *Conn, v interface{}) error {
//
// See the documentation for the encoding/json Marshal function for details
// about the conversion of JSON to a Go value.
func ReadJSON(c *Conn, v interface{}) error {
func (c *Conn) ReadJSON(v interface{}) error {
_, r, err := c.NextReader()
if err != nil {
return err

View File

@ -23,11 +23,11 @@ func TestJSON(t *testing.T) {
expect.A = 1
expect.B = "hello"
if err := WriteJSON(wc, &expect); err != nil {
if err := wc.WriteJSON(&expect); err != nil {
t.Fatal("write", err)
}
if err := ReadJSON(rc, &actual); err != nil {
if err := rc.ReadJSON(&actual); err != nil {
t.Fatal("read", err)
}