payload

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndHandle

func ListenAndHandle(r ReceiverFunc, h HandlerFunc, errReporter func(err error))

ListenAndHandle loops on payloads received using the given receiver and handles them with the given handler as they arrive. If an error happens during the process, ListenAndHandle will report it using the given errReporter and return. It silently stops when the provided receiver's underlying connection is closed.

func Send

func Send(ctx context.Context, conn *websocket.Conn, p *Payload) error

Send sends the given Payload on the given connection.

Types

type HandlerFunc

type HandlerFunc func(p *Payload) error

HandlerFunc is a function that handles a Payload.

type Payload

type Payload struct {
	// Opcode for the payload.
	Op int `json:"op"`
	// Event data.
	D json.RawMessage `json:"d"`
	// Sequence number, used for resuming sessions
	// and heartbeats. Only for Opcode 0.
	S int64 `json:"s,omitempty"`
	// The event name for this payload.
	// Only for Opcode 0.
	T string `json:"t,omitempty"`
}

Payload is the content of a Discord Gateway or Voice event.

func Recv

func Recv(ctx context.Context, connRMu *sync.Mutex, conn *websocket.Conn) (*Payload, error)

Recv receives a single message from the provided connection, ensuring no concurrent call to conn.ReadMessage can occur. It also takes care of optionally decompressing the message and decoding it into a payload.

func (*Payload) String

func (p *Payload) String() string

String implements fmt.Stringer.

type ReceiverFunc

type ReceiverFunc func() (*Payload, error)

ReceiverFunc is a function that receives a single Payload.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL