gateway

package module
v0.0.0-...-7f4bee4 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: BSD-3-Clause Imports: 0 Imported by: 0

README

gateway

Service for multiplexing many Discord websockets on top of any number of backends. Consists of 2 components: Gateway & State Cache

NOTE: This currently only supports Tatsu's specific use case. More backends will be written in the future as time permits.

A custom ETF parser was written from the ground up. During peak traffic, gateway uses ~4 cores for 720 shards.

State is stored in foundationdb and accessed via the State Cache (cmd/state).

Events are pushed to redis using RPUSH. The content is the d key of the event encoded as ETF.

Common Dependencies

  1. Ensure you have Go 1.13 or higher.
  2. Install foundationdb (both the server and clients package).
  3. Install redis.

Setting up the Gateway

  1. Add a variable in cmd/gateway/main.go named Token that contains your token.
  2. Enable modules export GO111MODULE=on
  3. Run go build in cmd/gateway
  4. To run, do ./gateway in cmd/gateway
  5. To only push certain event types to the event queue, set the WHITELIST_EVENTS environment variable e.g WHITELIST_EVENTS=MESSAGE_CREATE,MESSAGE_REACTION_ADD

Setting up the State

  1. Run go build in cmd/state
  2. To run, do ./state in cmd/state

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Data []byte
	Op   int
	Seq  int
	Type string
}

type Exporter

type Exporter interface {
}

type Receiver

type Receiver interface {
	Receive(*Event) error
}

Receiver receives events from a Discord websocket. Receivers must make sure to not handle events asynchronously since events must be handled in order per connection. Receivers must copy Events if it will be used after returning.

Jump to

Keyboard shortcuts

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