Help us shape the future of Go! Take the 2026 Go Developer Survey

hookbot

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TopicRE *regexp.Regexp = regexp.MustCompile("^(?:/unsafe)?/(?:pub|sub)/(.*)$")

The topic is everything after the "/pub/" or "/sub/" Do not capture the "/unsafe". See note in `Topic()`.

View Source
var UnsafeURI = regexp.MustCompile("^/unsafe/(pub|sub)/.*")

Functions

func ConfigureRouters

func ConfigureRouters(c *cli.Context, h *Hookbot)

func IsConnectionClose

func IsConnectionClose(err error) bool

func IsUnsafeRequest

func IsUnsafeRequest(r *http.Request) bool

Unsafe requests are those with URIs which have /unsafe/ as the second path component.

func RegisterRouter

func RegisterRouter(router Router)

func RequireUnsafeHeader

func RequireUnsafeHeader(wrapped http.Handler) http.HandlerFunc

func SecureEqual

func SecureEqual(x, y string) bool

func Sha1HMAC

func Sha1HMAC(key, payload string) string

func Topic

func Topic(r *http.Request) string

Types

type Hookbot

type Hookbot struct {
	http.Handler
	// contains filtered or unexported fields
}

func New

func New(key string) *Hookbot

func (*Hookbot) Add

func (h *Hookbot) Add(topic string) Listener

Return a new Listener which receives messages for `topic`.

func (*Hookbot) AddRouter

func (h *Hookbot) AddRouter(r Router)

Process messages for one router (one goroutine per topic)

func (*Hookbot) BothPubSub

func (h *Hookbot) BothPubSub(pub, sub http.Handler) http.Handler

BothPubSub is an endpoint which supports either publishing or subscribing. If it is a POST request, it is publishing, otherwise it is subscribing.

func (*Hookbot) Del

func (h *Hookbot) Del(l Listener)

Remove `l` from the set of interested listeners.

func (*Hookbot) IsKeyOK

func (h *Hookbot) IsKeyOK(w http.ResponseWriter, r *http.Request) bool

func (*Hookbot) KeyChecker

func (h *Hookbot) KeyChecker(wrapped http.Handler) http.HandlerFunc

func (*Hookbot) Loop

func (h *Hookbot) Loop()

Manage fanout from h.message onto listeners

func (*Hookbot) Publish

func (h *Hookbot) Publish(m Message) bool

Blocks until message has been published.

func (*Hookbot) ServePublish

func (h *Hookbot) ServePublish(w http.ResponseWriter, r *http.Request)

Publish a message via HTTP POST.

func (*Hookbot) ServeSubscribe

func (h *Hookbot) ServeSubscribe(conn *websocket.Conn, r *http.Request)

Subscribe to message via HTTP websocket.

func (*Hookbot) ShowStatus

func (h *Hookbot) ShowStatus(period time.Duration)

Every `period`, log a status line showing number of connected listeners, dropped messages, etc.

func (*Hookbot) Shutdown

func (h *Hookbot) Shutdown()

Shut down main loop and wait for all in-flight messages to send or timeout

func (*Hookbot) TimeoutSendWorker

func (h *Hookbot) TimeoutSendWorker(r chan MessageListener)

The TimeoutSendWorker passes messages from r onto individual listeners. It is responsible for dropping messages if the receiver can't keep up fast enough, or if the receiver disappears. Fun history: we used to spawn a goroutine per message, but this wasted large amounts of memory and performance.

type Listener

type Listener struct {
	Topic string
	// contains filtered or unexported fields
}

type Message

type Message struct {
	Topic string
	Body  []byte

	// Returns true if message is in flight, false if dropped.
	Sent chan bool // Signalled when messages have been strobed.
}

type MessageListener

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

Represents one {listener, message} pair, which is used for buffering and timing out messages in TimeoutSendWorker.

type MessageListeners

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

Analogous to MessageListener, but to represent {listeners, message} on a similar worker.

type Router

type Router interface {
	Name() string
	Topics() []string
	Route(in Message, publish func(Message) bool)
}

type WebsocketHandlerFunc

type WebsocketHandlerFunc func(*websocket.Conn, *http.Request)

func (WebsocketHandlerFunc) ServeHTTP

func (wrapped WebsocketHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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