realtime

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package realtime 提供共享身份入口和基于 Redis Stream 的跨实例恢复.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler func(context.Context, Principal, json.RawMessage) (any, error)

type Hub

type Hub struct {
	Redis     redis.UniversalClient
	Prefix    string
	Path      string
	Origins   []string
	Validate  func(context.Context, Principal) error
	Authorize func(context.Context, Principal, string) error
	// AuthorizeEvent checks permissions again before an inbox or channel event is delivered.
	AuthorizeEvent func(context.Context, Principal, string) error
	// Connected runs after authentication; Disconnected runs when that connection exits.
	Connected    func(context.Context, Principal) error
	Disconnected func(context.Context, Principal)
	Retention    time.Duration
	Limit        int64
	// contains filtered or unexported fields
}

func New

func New(client redis.UniversalClient, prefix, path string) *Hub

func (*Hub) Close

func (h *Hub) Close()

func (*Hub) Drain

func (h *Hub) Drain(ctx context.Context)

Drain 停接新连接并分散通知旧连接重连,超时后回收剩余连接。

func (*Hub) Handle

func (h *Hub) Handle(name string, handler Handler) error

Handle 注册普通业务函数, 无动态插件或自动扫描.

func (*Hub) Publish

func (h *Hub) Publish(ctx context.Context, to Principal, event string, data any) (string, error)

Publish 把事件存入接收者收件流; 每个设备独立维护确认位置.

func (*Hub) PublishChannel

func (h *Hub) PublishChannel(ctx context.Context, channel, event string, data any) (string, error)

func (*Hub) ServeHTTP

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

func (*Hub) Ticket

func (h *Hub) Ticket(ctx context.Context, p Principal, resume, locale string) (string, error)

Ticket 只能由已完成HTTP身份验证的业务签发, 恢复凭证绑定原身份和登录会话.

type Message

type Message struct {
	Type      string          `json:"type"`
	ID        string          `json:"id,omitempty"`
	RequestID string          `json:"request_id,omitempty"`
	Channel   string          `json:"channel,omitempty"`
	Ticket    string          `json:"ticket,omitempty"`
	Data      json.RawMessage `json:"data,omitempty"`
}

type Principal

type Principal struct {
	Realm     string `json:"realm"`
	Subject   string `json:"subject"`
	SessionID string `json:"session_id"`
}

Jump to

Keyboard shortcuts

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