Documentation
¶
Index ¶
- Variables
- type Connection
- type MemoryConnection
- type MemoryStore
- type Message
- type Meta
- type RedisConnection
- type RedisStore
- func (s *RedisStore) Close() error
- func (s *RedisStore) Get(ctx context.Context, id string) (Connection, error)
- func (s *RedisStore) List(ctx context.Context) ([]Connection, error)
- func (s *RedisStore) Register(ctx context.Context, meta *Meta) (Connection, error)
- func (s *RedisStore) Unregister(ctx context.Context, id string) error
- type RequestInfo
- type Store
- type Type
Constants ¶
This section is empty.
Variables ¶
var ErrSessionNotFound = fmt.Errorf("session not found")
ErrSessionNotFound is returned when a session is not found
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection interface { // EventQueue returns a read-only channel where outbound messages are published. EventQueue() <-chan *Message // Send pushes a message to the session. Send(ctx context.Context, msg *Message) error // Close gracefully terminates the session connection. Close(ctx context.Context) error // Meta returns metadata associated with the session. Meta() *Meta }
Connection represents an active session connection capable of sending messages.
type MemoryConnection ¶
type MemoryConnection struct {
// contains filtered or unexported fields
}
MemoryConnection implements Connection using in-memory storage
func (*MemoryConnection) Close ¶
func (c *MemoryConnection) Close(_ context.Context) error
Close implements Connection.Close
func (*MemoryConnection) EventQueue ¶
func (c *MemoryConnection) EventQueue() <-chan *Message
EventQueue implements Connection.EventQueue
func (*MemoryConnection) Meta ¶
func (c *MemoryConnection) Meta() *Meta
Meta implements Connection.Meta
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore implements Store using in-memory storage
func NewMemoryStore ¶
func NewMemoryStore(logger *zap.Logger) *MemoryStore
NewMemoryStore creates a new in-memory session store
func (*MemoryStore) Get ¶
func (s *MemoryStore) Get(_ context.Context, id string) (Connection, error)
Get implements Store.Get
func (*MemoryStore) List ¶
func (s *MemoryStore) List(_ context.Context) ([]Connection, error)
List implements Store.List
func (*MemoryStore) Register ¶
func (s *MemoryStore) Register(_ context.Context, meta *Meta) (Connection, error)
Register implements Store.Register
func (*MemoryStore) Unregister ¶
func (s *MemoryStore) Unregister(_ context.Context, id string) error
Unregister implements Store.Unregister
type Message ¶
type Message struct { Event string // Event type, e.g., "message", "close", "ping" Data []byte // Payload }
Message represents a unified message structure for session communication.
type Meta ¶
type Meta struct { ID string `json:"id"` // Unique session ID CreatedAt time.Time `json:"created_at"` // Timestamp of session creation Prefix string `json:"prefix"` // Optional namespace or application prefix Type string `json:"type"` // Connection type, e.g., "sse", "streamable" Request *RequestInfo `json:"request"` // Request information Extra []byte `json:"extra"` // Optional serialized extra data }
Meta holds immutable metadata about a session.
type RedisConnection ¶
type RedisConnection struct {
// contains filtered or unexported fields
}
RedisConnection implements Connection using Redis
func (*RedisConnection) Close ¶
func (c *RedisConnection) Close(ctx context.Context) error
Close implements Connection.Close
func (*RedisConnection) EventQueue ¶
func (c *RedisConnection) EventQueue() <-chan *Message
EventQueue implements Connection.EventQueue
func (*RedisConnection) Meta ¶
func (c *RedisConnection) Meta() *Meta
Meta implements Connection.Meta
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore implements Store using Redis
func NewRedisStore ¶
func NewRedisStore(logger *zap.Logger, cfg config.SessionRedisConfig) (*RedisStore, error)
NewRedisStore creates a new Redis-based session store func NewRedisStore(logger *zap.Logger, addr, username, password string, db int, topic string) (*RedisStore, error) {
func (*RedisStore) Get ¶
func (s *RedisStore) Get(ctx context.Context, id string) (Connection, error)
Get implements Store.Get
func (*RedisStore) List ¶
func (s *RedisStore) List(ctx context.Context) ([]Connection, error)
List implements Store.List
func (*RedisStore) Register ¶
func (s *RedisStore) Register(ctx context.Context, meta *Meta) (Connection, error)
Register implements Store.Register
func (*RedisStore) Unregister ¶
func (s *RedisStore) Unregister(ctx context.Context, id string) error
Unregister implements Store.Unregister
type RequestInfo ¶
type RequestInfo struct { Headers map[string]string `json:"headers"` Query map[string]string `json:"query"` Cookies map[string]string `json:"cookies"` }
RequestInfo holds information about the request that created the session.
type Store ¶
type Store interface { // Register creates and registers a new session connection. Register(ctx context.Context, meta *Meta) (Connection, error) // Get retrieves an active session connection by ID. Get(ctx context.Context, id string) (Connection, error) // Unregister removes a session connection by ID. Unregister(ctx context.Context, id string) error // List returns all currently active session connections. List(ctx context.Context) ([]Connection, error) }
Store manages the lifecycle and lookup of active session connections.