mirror of https://github.com/gorilla/websocket.git
Added WriteJSON/ReadJSON deprecated methods for backwards compatibility.
This commit is contained in:
parent
bc91df87fe
commit
9d9a930c1e
10
json.go
10
json.go
|
@ -8,6 +8,11 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DEPRECATED: use c.WriteJSON instead.
|
||||||
|
func WriteJSON(c *Conn, v interface{}) error {
|
||||||
|
return c.WriteJSON(v)
|
||||||
|
}
|
||||||
|
|
||||||
// WriteJSON writes the JSON encoding of v to the connection.
|
// WriteJSON writes the JSON encoding of v to the connection.
|
||||||
//
|
//
|
||||||
// See the documentation for encoding/json Marshal for details about the
|
// See the documentation for encoding/json Marshal for details about the
|
||||||
|
@ -25,6 +30,11 @@ func (c *Conn) WriteJSON(v interface{}) error {
|
||||||
return err2
|
return err2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DEPRECATED: use c.WriteJSON instead.
|
||||||
|
func ReadJSON(c *Conn, v interface{}) error {
|
||||||
|
return c.ReadJSON(v)
|
||||||
|
}
|
||||||
|
|
||||||
// ReadJSON reads the next JSON-encoded message from the connection and stores
|
// ReadJSON reads the next JSON-encoded message from the connection and stores
|
||||||
// it in the value pointed to by v.
|
// it in the value pointed to by v.
|
||||||
//
|
//
|
||||||
|
|
|
@ -23,10 +23,18 @@ func TestJSON(t *testing.T) {
|
||||||
expect.A = 1
|
expect.A = 1
|
||||||
expect.B = "hello"
|
expect.B = "hello"
|
||||||
|
|
||||||
|
if err := WriteJSON(wc, &expect); err != nil {
|
||||||
|
t.Fatal("write", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := wc.WriteJSON(&expect); err != nil {
|
if err := wc.WriteJSON(&expect); err != nil {
|
||||||
t.Fatal("write", err)
|
t.Fatal("write", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := ReadJSON(rc, &expect); err != nil {
|
||||||
|
t.Fatal("read", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := rc.ReadJSON(&actual); err != nil {
|
if err := rc.ReadJSON(&actual); err != nil {
|
||||||
t.Fatal("read", err)
|
t.Fatal("read", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue