const finalBit … const rsv1Bit … const rsv2Bit … const rsv3Bit … const maskBit … const maxFrameHeaderSize … const maxControlFramePayloadSize … const writeWait … const defaultReadBufferSize … const defaultWriteBufferSize … const continuationFrame … const noFrame … const CloseNormalClosure … const CloseGoingAway … const CloseProtocolError … const CloseUnsupportedData … const CloseNoStatusReceived … const CloseAbnormalClosure … const CloseInvalidFramePayloadData … const ClosePolicyViolation … const CloseMessageTooBig … const CloseMandatoryExtension … const CloseInternalServerErr … const CloseServiceRestart … const CloseTryAgainLater … const CloseTLSHandshake … const TextMessage … const BinaryMessage … const CloseMessage … const PingMessage … const PongMessage … var ErrCloseSent … var ErrReadLimit … type netError … func (e *netError) Error() string { … } func (e *netError) Temporary() bool { … } func (e *netError) Timeout() bool { … } type CloseError … func (e *CloseError) Error() string { … } // IsCloseError returns boolean indicating whether the error is a *CloseError // with one of the specified codes. func IsCloseError(err error, codes ...int) bool { … } // IsUnexpectedCloseError returns boolean indicating whether the error is a // *CloseError with a code not in the list of expected codes. func IsUnexpectedCloseError(err error, expectedCodes ...int) bool { … } var errWriteTimeout … var errUnexpectedEOF … var errBadWriteOpCode … var errWriteClosed … var errInvalidControlFrame … func newMaskKey() [4]byte { … } func hideTempErr(err error) error { … } func isControl(frameType int) bool { … } func isData(frameType int) bool { … } var validReceivedCloseCodes … func isValidReceivedCloseCode(code int) bool { … } type BufferPool … type writePoolData … type Conn … func newConn(conn net.Conn, isServer bool, readBufferSize, writeBufferSize int, writeBufferPool BufferPool, br *bufio.Reader, writeBuf []byte) *Conn { … } // setReadRemaining tracks the number of bytes remaining on the connection. If n // overflows, an ErrReadLimit is returned. func (c *Conn) setReadRemaining(n int64) error { … } // Subprotocol returns the negotiated protocol for the connection. func (c *Conn) Subprotocol() string { … } // Close closes the underlying network connection without sending or waiting // for a close message. func (c *Conn) Close() error { … } // LocalAddr returns the local network address. func (c *Conn) LocalAddr() net.Addr { … } // RemoteAddr returns the remote network address. func (c *Conn) RemoteAddr() net.Addr { … } func (c *Conn) writeFatal(err error) error { … } func (c *Conn) read(n int) ([]byte, error) { … } func (c *Conn) write(frameType int, deadline time.Time, buf0, buf1 []byte) error { … } func (c *Conn) writeBufs(bufs ...[]byte) error { … } // WriteControl writes a control message with the given deadline. The allowed // message types are CloseMessage, PingMessage and PongMessage. func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) error { … } // beginMessage prepares a connection and message writer for a new message. func (c *Conn) beginMessage(mw *messageWriter, messageType int) error { … } // NextWriter returns a writer for the next message to send. The writer's Close // method flushes the complete message to the network. // // There can be at most one open writer on a connection. NextWriter closes the // previous writer if the application has not already done so. // // All message types (TextMessage, BinaryMessage, CloseMessage, PingMessage and // PongMessage) are supported. func (c *Conn) NextWriter(messageType int) (io.WriteCloser, error) { … } type messageWriter … func (w *messageWriter) endMessage(err error) error { … } // flushFrame writes buffered data and extra as a frame to the network. The // final argument indicates that this is the last frame in the message. func (w *messageWriter) flushFrame(final bool, extra []byte) error { … } func (w *messageWriter) ncopy(max int) (int, error) { … } func (w *messageWriter) Write(p []byte) (int, error) { … } func (w *messageWriter) WriteString(p string) (int, error) { … } func (w *messageWriter) ReadFrom(r io.Reader) (nn int64, err error) { … } func (w *messageWriter) Close() error { … } // WritePreparedMessage writes prepared message into connection. func (c *Conn) WritePreparedMessage(pm *PreparedMessage) error { … } // WriteMessage is a helper method for getting a writer using NextWriter, // writing the message and closing the writer. func (c *Conn) WriteMessage(messageType int, data []byte) error { … } // SetWriteDeadline sets the write deadline on the underlying network // connection. After a write has timed out, the websocket state is corrupt and // all future writes will return an error. A zero value for t means writes will // not time out. func (c *Conn) SetWriteDeadline(t time.Time) error { … } func (c *Conn) advanceFrame() (int, error) { … } func (c *Conn) handleProtocolError(message string) error { … } // NextReader returns the next data message received from the peer. The // returned messageType is either TextMessage or BinaryMessage. // // There can be at most one open reader on a connection. NextReader discards // the previous message if the application has not already consumed it. // // Applications must break out of the application's read loop when this method // returns a non-nil error value. Errors returned from this method are // permanent. Once this method returns a non-nil error, all subsequent calls to // this method return the same error. func (c *Conn) NextReader() (messageType int, r io.Reader, err error) { … } type messageReader … func (r *messageReader) Read(b []byte) (int, error) { … } func (r *messageReader) Close() error { … } // ReadMessage is a helper method for getting a reader using NextReader and // reading from that reader to a buffer. func (c *Conn) ReadMessage() (messageType int, p []byte, err error) { … } // SetReadDeadline sets the read deadline on the underlying network connection. // After a read has timed out, the websocket connection state is corrupt and // all future reads will return an error. A zero value for t means reads will // not time out. func (c *Conn) SetReadDeadline(t time.Time) error { … } // SetReadLimit sets the maximum size in bytes for a message read from the peer. If a // message exceeds the limit, the connection sends a close message to the peer // and returns ErrReadLimit to the application. func (c *Conn) SetReadLimit(limit int64) { … } // CloseHandler returns the current close handler func (c *Conn) CloseHandler() func(code int, text string) error { … } // SetCloseHandler sets the handler for close messages received from the peer. // The code argument to h is the received close code or CloseNoStatusReceived // if the close message is empty. The default close handler sends a close // message back to the peer. // // The handler function is called from the NextReader, ReadMessage and message // reader Read methods. The application must read the connection to process // close messages as described in the section on Control Messages above. // // The connection read methods return a CloseError when a close message is // received. Most applications should handle close messages as part of their // normal error handling. Applications should only set a close handler when the // application must perform some action before sending a close message back to // the peer. func (c *Conn) SetCloseHandler(h func(code int, text string) error) { … } // PingHandler returns the current ping handler func (c *Conn) PingHandler() func(appData string) error { … } // SetPingHandler sets the handler for ping messages received from the peer. // The appData argument to h is the PING message application data. The default // ping handler sends a pong to the peer. // // The handler function is called from the NextReader, ReadMessage and message // reader Read methods. The application must read the connection to process // ping messages as described in the section on Control Messages above. func (c *Conn) SetPingHandler(h func(appData string) error) { … } // PongHandler returns the current pong handler func (c *Conn) PongHandler() func(appData string) error { … } // SetPongHandler sets the handler for pong messages received from the peer. // The appData argument to h is the PONG message application data. The default // pong handler does nothing. // // The handler function is called from the NextReader, ReadMessage and message // reader Read methods. The application must read the connection to process // pong messages as described in the section on Control Messages above. func (c *Conn) SetPongHandler(h func(appData string) error) { … } // UnderlyingConn returns the internal net.Conn. This can be used to further // modifications to connection specific flags. func (c *Conn) UnderlyingConn() net.Conn { … } // EnableWriteCompression enables and disables write compression of // subsequent text and binary messages. This function is a noop if // compression was not negotiated with the peer. func (c *Conn) EnableWriteCompression(enable bool) { … } // SetCompressionLevel sets the flate compression level for subsequent text and // binary messages. This function is a noop if compression was not negotiated // with the peer. See the compress/flate package for a description of // compression levels. func (c *Conn) SetCompressionLevel(level int) error { … } // FormatCloseMessage formats closeCode and text as a WebSocket close message. // An empty message is returned for code CloseNoStatusReceived. func FormatCloseMessage(closeCode int, text string) []byte { … }