diff --git a/README.md b/README.md index cafb0b975fba09278df6a13eb315fe162847c2cf..3328e40ddf638b2e858e2c748ac5b59ef6ebff7e 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ This package is the community standard but it is very old and over time has accumulated cruft. There are many ways to do the same thing and the API overall is just not very clear. -The callback hooks are also confusing. The API for this library has been designed +The callback hooks . The API for this library has been designed such that there is only one way to do things and callbacks have been avoided. Performance sensitive applications should use ws/wscore directly. @@ -42,3 +42,9 @@ Performance sensitive applications should use ws/wscore directly. This library has an extremely flexible API but that comes at a cost of usability and clarity. Its just not clear and simple how to do things in a safe manner. + +## TODO + +- [ ] Fully implement. +- [ ] Decide whether we want to do WebSocket pings by default maybe every 30s? +- [ ] diff --git a/wscore/header.go b/header.go similarity index 64% rename from wscore/header.go rename to header.go index bcbd41eb02b2db5d0564f7cf6e80e5e6559fed50..42eb6143deeca179b62648ff1c8e334405a6ea5a 100644 --- a/wscore/header.go +++ b/header.go @@ -1,17 +1,18 @@ -package wscore +package ws import ( "io" ) -// Header represents a WebSocket frame header. +// header represents a WebSocket frame header. // See https://tools.ietf.org/html/rfc6455#section-5.2 -type Header struct { +// The fields are exported for easy printing for debugging. +type header struct { Fin bool Rsv1 bool Rsv2 bool Rsv3 bool - Opcode Opcode + Opcode opcode PayloadLength int64 @@ -20,7 +21,7 @@ type Header struct { } // Bytes returns the bytes of the header. -func (h Header) Bytes() []byte { +func (h header) Bytes() []byte { panic("TODO") } diff --git a/wscore/mask.go b/mask.go similarity index 87% rename from wscore/mask.go rename to mask.go index c6c08ccd1e85ca8ff821ec957c64f2303fd20326..0055eb78672fe7ae9d393ae41ada5a204d8932b7 100644 --- a/wscore/mask.go +++ b/mask.go @@ -1,4 +1,4 @@ -package wscore +package ws // Mask applies the websocket masking algorithm to p // with the given key where the first 3 bits of pos @@ -10,6 +10,6 @@ package wscore // // For targets that do not support unsafe, please report an issue. // There is a mask by byte function below that will be used for such targets. -func Mask(key [4]byte, pos int, p []byte) int { +func mask(key [4]byte, pos int, p []byte) int { panic("TODO") } diff --git a/opcode.go b/opcode.go new file mode 100644 index 0000000000000000000000000000000000000000..5616bb578b15bbbebcd6531aef73545ede875202 --- /dev/null +++ b/opcode.go @@ -0,0 +1,17 @@ +package ws + +// opcode represents a WebSocket Opcode. +//go:generate stringer -type=opcode +type opcode int + +// opcode constants. +const ( + opContinuation opcode = iota + opText + opBinary + // 3 - 7 are reserved for further non-control frames. + opClose opcode = 8 + iota + opPing + opPong + // 11-16 are reserved for further control frames. +) diff --git a/wscore/opcode_string.go b/opcode_string.go similarity index 98% rename from wscore/opcode_string.go rename to opcode_string.go index 8ed5c1c700689582e53dee8fb6963726ad686fea..61531ac1fab6140370fad5b94e4e8411aecca8ca 100644 --- a/wscore/opcode_string.go +++ b/opcode_string.go @@ -1,6 +1,6 @@ // Code generated by "stringer -type=Opcode"; DO NOT EDIT. -package wscore +package ws import "strconv" diff --git a/ws.go b/ws.go index 7ec54ed7a82e48c934e37886a38b4cae3eab13c8..68d3cf9b41d94fd00f821542d8492e075fa6f8d6 100644 --- a/ws.go +++ b/ws.go @@ -10,8 +10,7 @@ const ( ) // Conn represents a WebSocket connection. -type Conn struct { -} +type Conn struct{} // Subprotocol returns the negotiated subprotocol. // An empty string means the default protocol. @@ -47,8 +46,7 @@ func (c *Conn) Close(code StatusCode, reason string) error { // MessageWriter enables writing to a WebSocket connection. // Ensure you close the MessageWriter once you have written to entire message. -type MessageWriter struct { -} +type MessageWriter struct{} // Write writes the given bytes to the WebSocket connection. // The frame will automatically be fragmented as appropriate @@ -65,8 +63,7 @@ func (w *MessageWriter) Close() error { } // MessageReader enables reading a data frame from the WebSocket connection. -type MessageReader struct { -} +type MessageReader struct{} // SetContext bounds the read operation to the ctx. // By default, the context is the one passed to conn.ReadMessage. diff --git a/wscore/opcode.go b/wscore/opcode.go deleted file mode 100644 index 878eb80ec93a7150b34989792e3e52a7a5c9f7b2..0000000000000000000000000000000000000000 --- a/wscore/opcode.go +++ /dev/null @@ -1,17 +0,0 @@ -package wscore - -// Opcode represents a WebSocket Opcode. -//go:generate stringer -type=Opcode -type Opcode int - -// Opcode constants. -const ( - OpContinuation Opcode = iota - OpText - OpBinary - // 3 - 7 are reserved for further non-control frames. - OpClose Opcode = 8 + iota - OpPing - OpPong - // 11-16 are reserved for further control frames. -)