mirror of https://github.com/gorilla/websocket.git
Use WriteJSON and ReadJSON on Conn struct.
This commit is contained in:
parent
273ecadfca
commit
bc91df87fe
4
json.go
4
json.go
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue