pubsub

package
v0.0.0-...-4623cc2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	WebsocketReadTimeout  = 30 * time.Second
	WebsocketWriteTimeout = 10 * time.Second
)

Variables

View Source
var PubSubHTTPHandlerLogger = slogutil.NewLogger("pubsub-http-handler")

Functions

This section is empty.

Types

type Delegate

type Delegate interface {
	Accept(r *http.Request) (channelName string, err error)
	OnRedisSubscribe(r *http.Request) error
}

type HTTPHandler

type HTTPHandler struct {
	RedisHub      RedisHub
	Delegate      Delegate
	OriginMatcher WebsocketOriginMatcher
}

HTTPHandler receives incoming websocket messages and delegates them to the delegate. For each websocket connection, a redis pubsub connection is established. Every message from the redis pubsub connection is forwarded to the websocket connection verbatim.

func (*HTTPHandler) ServeHTTP

func (h *HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Publisher

type Publisher struct {
	RedisPool RedisPool
}

func (*Publisher) Publish

func (p *Publisher) Publish(ctx context.Context, channelName string, data []byte) error

type RedisHub

type RedisHub interface {
	Subscribe(channelName string) (chan *redis.Message, func())
}

type RedisPool

type RedisPool interface {
	Get() *redis.Client
}

type WebsocketOriginMatcher

type WebsocketOriginMatcher interface {
	MatchOrigin(origin string) bool
}

type WebsocketOutgoingMessage

type WebsocketOutgoingMessage struct {
	MessageType websocket.MessageType
	Data        []byte
}

Jump to

Keyboard shortcuts

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