mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-04 12:10:21 -05:00
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.17.1 to 2.17.2. - [Release notes](https://github.com/onsi/ginkgo/releases) - [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/ginkgo/compare/v2.17.1...v2.17.2) --- updated-dependencies: - dependency-name: github.com/onsi/ginkgo/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
/*
|
|
Package wsutil provides utilities for working with WebSocket protocol.
|
|
|
|
Overview:
|
|
|
|
// Read masked text message from peer and check utf8 encoding.
|
|
header, err := ws.ReadHeader(conn)
|
|
if err != nil {
|
|
// handle err
|
|
}
|
|
|
|
// Prepare to read payload.
|
|
r := io.LimitReader(conn, header.Length)
|
|
r = wsutil.NewCipherReader(r, header.Mask)
|
|
r = wsutil.NewUTF8Reader(r)
|
|
|
|
payload, err := ioutil.ReadAll(r)
|
|
if err != nil {
|
|
// handle err
|
|
}
|
|
|
|
You could get the same behavior using just `wsutil.Reader`:
|
|
|
|
r := wsutil.Reader{
|
|
Source: conn,
|
|
CheckUTF8: true,
|
|
}
|
|
|
|
payload, err := ioutil.ReadAll(r)
|
|
if err != nil {
|
|
// handle err
|
|
}
|
|
|
|
Or even simplest:
|
|
|
|
payload, err := wsutil.ReadClientText(conn)
|
|
if err != nil {
|
|
// handle err
|
|
}
|
|
|
|
Package is also exports tools for buffered writing:
|
|
|
|
// Create buffered writer, that will buffer output bytes and send them as
|
|
// 128-length fragments (with exception on large writes, see the doc).
|
|
writer := wsutil.NewWriterSize(conn, ws.StateServerSide, ws.OpText, 128)
|
|
|
|
_, err := io.CopyN(writer, rand.Reader, 100)
|
|
if err == nil {
|
|
err = writer.Flush()
|
|
}
|
|
if err != nil {
|
|
// handle error
|
|
}
|
|
|
|
For more utils and helpers see the documentation.
|
|
*/
|
|
package wsutil
|