Documentation ¶
Overview ¶
package twid implements a server that can load and run multiple Twid modules. These modules can form a complete Twid server that interacts with Twilio over its REST and webhooks API.
For examples on how to use this package, see github.com/diamondburned/twidiscord.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CommandHandler ¶
type CommandHandler interface { Handler // Command returns the module's root command. Commands are checked against // collisions. Command() twicli.Command }
CommandHandler is a module that uses the twicli.Command API.
type Config ¶
type Config struct { HTTP struct { ListenAddr cfgutil.EnvString `toml:"listen_addr" json:"listen_addr"` } `toml:"http" json:"http"` }
Config is the twid config block.
type ConfigType ¶
type ConfigType string
ConfigType is the type of the configuration file, e.g. "toml" or "json".
const ( TOMLConfig ConfigType = "toml" JSONConfig ConfigType = "json" )
type HTTPCommander ¶
type HTTPCommander interface { Handler // HTTPHandler returns the HTTP handler for the module. HTTPHandler() http.Handler // HTTPPrefix returns the HTTP prefix that the module will serve on. The // prefix must not contain a trailing slash. HTTPPrefix() string }
HTTPCommander is a module that implements HTTP serving.
type Handler ¶
type Handler interface { // Config returns the module's configuration. The configuration is assumed // to be the root structure, and each module should wrap its configuration // in a block named after the module. Config() any // Start starts the module. Start(ctx context.Context) error }
Handler is a handler instance created by a registered module.
type Loader ¶
type Loader struct { Config struct { Twid Config `toml:"twid" json:"twid"` Twipi twipi.Config `toml:"twipi" json:"twipi"` } // contains filtered or unexported fields }
Loader is a module loader. It assists in loading a list of modules and starting them.
func NewGlobalLoader ¶
func NewGlobalLoader() *Loader
NewGlobalLoader creates a new loader with the global modules.
func (*Loader) LoadConfig ¶
LoadConfig loads the configuration from the given bytes into all the module handlers. configType determines the type of the configuration file, e.g. "toml" or "json".
func (*Loader) LoadConfigFile ¶
LoadConfigFile loads the configuration file from the given path into all the module handlers.
type MessageHandler ¶
type MessageHandler interface { Handler // HandleMessage handles the given message. Each HandleMessage call is // assumed to be in a separate goroutine. HandleMessage(ctx context.Context, msg twipi.Message) }
MessageHandler is a module that can handle a Twipi message. This is commonly used as an alternative for CommandHandler.
type Module ¶
type Module struct { // Name is the name of the module. Name string // New is the constructor that creates a new Handler. New func() Handler }
Module is a module that can be loaded by the twid server.
type TwipiHandler ¶
type TwipiHandler interface { Handler // BindTwipi binds the configured Twipi server to the module. BindTwipi(*twipi.ConfiguredServer) }
TwipiHandler is a module that can bind a Twipi server.