Golang中的Web套接字出现问题

The following function works as follows. The send channel receives a new msg of type Message (a struct defined else where) write to the websocket. It seems that client.socket.WriteJSON(msg) returns an error. It print "websocket: close sent" . I attempted to debug things and I realized a few things. msg is generated properly, the error will occur if I try to use writeJSON on an object, and the error only occurs if the writeJSON occurs after the msg := range client.send . Sorry if this was confusing. I'm happy to clarify.

  func (client *Client) Write(){
        for msg := range client.send {
            if err := client.socket.WriteJSON(msg); err != nil {
                fmt.Println(err)
                break
            }
        }
        client.socket.Close();
    }