mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
Remove some redundancy in websocketconn naming.
Rename websocketconn.WebSocketConn to websocketconn.Conn, and websocketconn.NewWebSocketConn to websocketconn.New Following the guidelines at https://blog.golang.org/package-names#TOC_3%2e
This commit is contained in:
parent
5b01df9030
commit
e47dd5e2b4
4 changed files with 13 additions and 13 deletions
|
@ -9,13 +9,13 @@ import (
|
|||
|
||||
// An abstraction that makes an underlying WebSocket connection look like an
|
||||
// io.ReadWriteCloser.
|
||||
type WebSocketConn struct {
|
||||
type Conn struct {
|
||||
Ws *websocket.Conn
|
||||
r io.Reader
|
||||
}
|
||||
|
||||
// Implements io.Reader.
|
||||
func (conn *WebSocketConn) Read(b []byte) (n int, err error) {
|
||||
func (conn *Conn) Read(b []byte) (n int, err error) {
|
||||
var opCode int
|
||||
if conn.r == nil {
|
||||
// New message
|
||||
|
@ -43,7 +43,7 @@ func (conn *WebSocketConn) Read(b []byte) (n int, err error) {
|
|||
}
|
||||
|
||||
// Implements io.Writer.
|
||||
func (conn *WebSocketConn) Write(b []byte) (n int, err error) {
|
||||
func (conn *Conn) Write(b []byte) (n int, err error) {
|
||||
var w io.WriteCloser
|
||||
if w, err = conn.Ws.NextWriter(websocket.BinaryMessage); err != nil {
|
||||
return
|
||||
|
@ -56,15 +56,15 @@ func (conn *WebSocketConn) Write(b []byte) (n int, err error) {
|
|||
}
|
||||
|
||||
// Implements io.Closer.
|
||||
func (conn *WebSocketConn) Close() error {
|
||||
func (conn *Conn) Close() error {
|
||||
// Ignore any error in trying to write a Close frame.
|
||||
_ = conn.Ws.WriteControl(websocket.CloseMessage, []byte{}, time.Now().Add(time.Second))
|
||||
return conn.Ws.Close()
|
||||
}
|
||||
|
||||
// Create a new WebSocketConn.
|
||||
func NewWebSocketConn(ws *websocket.Conn) WebSocketConn {
|
||||
var conn WebSocketConn
|
||||
// Create a new Conn.
|
||||
func New(ws *websocket.Conn) Conn {
|
||||
var conn Conn
|
||||
conn.Ws = ws
|
||||
return conn
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue