mux

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler implements the help handler.

type Helper

type Helper interface {
	Help(io.Writer) error
}

type Mux

type Mux struct {
	sync.RWMutex
	ToBot         hugot.Handler                     // Handles message aimed directly at the bot
	RawHandlers   []hugot.Handler                   // Raw handlers
	BGHandlers    []hugot.BackgroundHandler         // Long running background handlers
	Webhooks      map[string]hugot.WebHookHandler   // WebHooks
	HearsHandlers map[*regexp.Regexp][]hears.Hearer // Hearing handlers
	// contains filtered or unexported fields
}

Mux is a Handler that multiplexes messages to a set of Command, Hears, and Raw handlers.

func New

func New(name, desc string, opts ...Opt) *Mux

New creates a new Mux.

func (*Mux) Background

func (mx *Mux) Background(hs ...hugot.BackgroundHandler) error

Background adds the provided handler to the Mux. It will be started with the Mux is started.

func (*Mux) CommandSetup

func (mx *Mux) CommandSetup(cmd *command.Command) error

func (*Mux) Describe

func (mx *Mux) Describe() (string, string)

Describe implements the Describe method of Handler for the Mux

func (*Mux) HandleHTTP

func (mx *Mux) HandleHTTP(h hugot.WebHookHandler)

HandleHTTP registers h as a WebHook handler. The name of the Mux, and the name of the handler are used to construct a unique URL that can be used to send web requests to this handler

func (*Mux) Hears

func (mx *Mux) Hears(hs ...hears.Hearer) error

Hears adds the provided handler to the mux. all messages matching the hears patterns will be forwarded to the handler.

func (*Mux) ProcessMessage

func (mx *Mux) ProcessMessage(ctx context.Context, w hugot.ResponseWriter, m *hugot.Message) error

ProcessMessage implements the Handler interface. Message will first be passed to any registered RawHandlers. If the message has been deemed, by the Adapter to have been sent directly to the bot, any comand handlers will be processed. Then, if appropriate, the message will be matched against any Hears patterns and all matching Heard functions will then be called. Any unrecognized errors from the Command handlers will be passed back to the user that sent us the message.

func (*Mux) Raw

func (mx *Mux) Raw(hs ...hugot.Handler) error

Raw adds the provided handlers to the Mux. All messages sent to the mux will be forwarded to this handler.

func (*Mux) ServeHTTP

func (mx *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP iplements http.ServeHTTP for a Mux to allow it to act as a web server.

func (*Mux) SetAdapter

func (mx *Mux) SetAdapter(a hugot.Adapter)

SetAdapter sets the adapter on all the webhook of this mux.

func (*Mux) SetURL

func (mx *Mux) SetURL(b *url.URL)

SetURL sets the base URL for this mux's web hooks.

func (*Mux) StartBackground

func (mx *Mux) StartBackground(ctx context.Context, w hugot.ResponseWriter)

StartBackground starts any registered background handlers.

func (*Mux) URL

func (mx *Mux) URL() *url.URL

URL returns the base URL for this Mux

type Opt

type Opt func(*Mux)

Opt functions are used to set options on the Mux

func WithStore

func WithStore(s storage.Storer) Opt

WithStore is a Mux option to set the store to be used for managing aliases, and property lookup.

Jump to

Keyboard shortcuts

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