Documentation ¶
Index ¶
- Variables
- func ConfigureRouters(c *cli.Context, h *Hookbot)
- func IsConnectionClose(err error) bool
- func IsUnsafeRequest(r *http.Request) bool
- func RegisterRouter(router Router)
- func RequireUnsafeHeader(wrapped http.Handler) http.HandlerFunc
- func SecureEqual(x, y string) bool
- func Sha1HMAC(key, payload string) string
- func Topic(r *http.Request) string
- type Hookbot
- func (h *Hookbot) Add(topic string) Listener
- func (h *Hookbot) AddRouter(r Router)
- func (h *Hookbot) BothPubSub(pub, sub http.Handler) http.Handler
- func (h *Hookbot) Del(l Listener)
- func (h *Hookbot) IsKeyOK(w http.ResponseWriter, r *http.Request) bool
- func (h *Hookbot) KeyChecker(wrapped http.Handler) http.HandlerFunc
- func (h *Hookbot) Loop()
- func (h *Hookbot) Publish(m Message) bool
- func (h *Hookbot) ServePublish(w http.ResponseWriter, r *http.Request)
- func (h *Hookbot) ServeSubscribe(conn *websocket.Conn, r *http.Request)
- func (h *Hookbot) ShowStatus(period time.Duration)
- func (h *Hookbot) Shutdown()
- func (h *Hookbot) TimeoutSendWorker(r chan MessageListener)
- type Listener
- type Message
- type MessageListener
- type MessageListeners
- type Router
- type WebsocketHandlerFunc
Constants ¶
This section is empty.
Variables ¶
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()`.
var UnsafeURI = regexp.MustCompile("^/unsafe/(pub|sub)/.*")
Functions ¶
func ConfigureRouters ¶
func IsConnectionClose ¶
func IsUnsafeRequest ¶
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 ¶
Types ¶
type Hookbot ¶
func (*Hookbot) BothPubSub ¶
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) KeyChecker ¶
func (h *Hookbot) KeyChecker(wrapped http.Handler) http.HandlerFunc
func (*Hookbot) ServePublish ¶
func (h *Hookbot) ServePublish(w http.ResponseWriter, r *http.Request)
Publish a message via HTTP POST.
func (*Hookbot) ServeSubscribe ¶
Subscribe to message via HTTP websocket.
func (*Hookbot) ShowStatus ¶
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 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 WebsocketHandlerFunc ¶
func (WebsocketHandlerFunc) ServeHTTP ¶
func (wrapped WebsocketHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)