Documentation
¶
Index ¶
- type FrameMessage
- type Handler
- type Option
- type OverflowPolicy
- type RemovalPolicy
- type Session
- func (s *Session) Error() error
- func (s *Session) EventsAfter(lastID uint64) [][]byte
- func (s *Session) LastRequestID() jsonrpc.RequestId
- func (s *Session) MarkActiveWithWriter(w io.Writer)
- func (s *Session) MarkDetached()
- func (s *Session) NextRequestID() jsonrpc.RequestId
- func (s *Session) SendData(ctx context.Context, data []byte)
- func (s *Session) SendError(ctx context.Context, error *jsonrpc.Error)
- func (s *Session) SendRequest(ctx context.Context, request *jsonrpc.Request)
- func (s *Session) SendResponse(ctx context.Context, response *jsonrpc.Response)
- func (s *Session) SetError(err error)
- func (s *Session) Touch()
- func (s *Session) WriterGeneration() uint64
- type SessionState
- type SessionStore
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FrameMessage ¶
FrameMessage is a function type that allows wrapping of the message before sending it to the client
type Handler ¶
type Handler struct {
Sessions SessionStore
Logger jsonrpc.Logger // Logger for error messages
}
Handler represents a jsonrpc endpoint
func NewHandler ¶
func NewHandler() *Handler
type Option ¶
type Option func(s *Session)
Option represents option
func WithEventBuffer ¶ added in v0.6.0
WithEventBuffer sets size of in-memory event buffer for session so that server can re-deliver messages on Last-Event-ID reconnect.
func WithEventOverflowPolicy ¶ added in v0.15.0
func WithEventOverflowPolicy(policy OverflowPolicy) Option
WithEventOverflowPolicy sets the overflow policy for event buffering.
func WithFramer ¶
func WithFramer(framer FrameMessage) Option
type OverflowPolicy ¶ added in v0.15.0
type OverflowPolicy int
OverflowPolicy defines how the event buffer handles overflow.
const ( // OverflowDropOldest drops the oldest events when the buffer is full. OverflowDropOldest OverflowPolicy = iota // OverflowMark sets an overflow flag when buffer would overflow, while still dropping oldest. OverflowMark )
type RemovalPolicy ¶ added in v0.15.0
type RemovalPolicy int
RemovalPolicy determines when a session should be removed from the session store.
const ( // RemovalOnDisconnect removes session as soon as streaming connection closes. // Useful for strict cleanup behavior. RemovalOnDisconnect RemovalPolicy = iota // RemovalAfterGrace keeps session for a grace period to allow quick reconnects. RemovalAfterGrace // RemovalAfterIdle removes session after it has been idle for a configured TTL. RemovalAfterIdle // RemovalManual leaves removal entirely to explicit DELETE or external cleanup. RemovalManual )
type Session ¶
type Session struct {
Id string `json:"id"`
RoundTrips *transport.RoundTrips
Writer io.Writer
Handler transport.Handler
RequestIdSeq uint64
sync.Mutex
// Lifecycle metadata
CreatedAt time.Time
LastSeen time.Time
DetachedAt *time.Time
State SessionState
WriterPresent bool
// contains filtered or unexported fields
}
func NewSession ¶
func (*Session) EventsAfter ¶ added in v0.6.0
EventsAfter returns buffered framed messages with id greater than lastID.
func (*Session) LastRequestID ¶ added in v0.7.3
LastRequestID returns the most recently generated request id without mutating the underlying sequence. It is concurrency-safe and can be used to inspect the current sequence value.
func (*Session) MarkActiveWithWriter ¶ added in v0.15.0
MarkActiveWithWriter re-attaches a writer and marks session active.
func (*Session) MarkDetached ¶ added in v0.15.0
func (s *Session) MarkDetached()
MarkDetached marks session as detached and records time.
func (*Session) NextRequestID ¶ added in v0.7.1
func (*Session) SendRequest ¶
SendRequest sends response
func (*Session) SendResponse ¶
SendResponse sends response
func (*Session) Touch ¶ added in v0.15.0
func (s *Session) Touch()
Touch updates LastSeen timestamp.
func (*Session) WriterGeneration ¶ added in v0.15.0
WriterGeneration returns the current writer attachment generation.
type SessionState ¶ added in v0.15.0
type SessionState int
SessionState represents lifecycle state of a session.
const ( SessionStateActive SessionState = iota SessionStateDetached SessionStateClosed )
type SessionStore ¶ added in v0.15.0
type SessionStore interface {
Get(id string) (*Session, bool)
Put(id string, s *Session)
Delete(id string)
Range(func(id string, s *Session) bool)
}
SessionStore abstracts session persistence. Default implementation is in-memory; custom stores (e.g., Redis) can implement this interface.
func NewMemorySessionStore ¶ added in v0.15.0
func NewMemorySessionStore() SessionStore
NewMemorySessionStore creates an in-memory SessionStore.
type Transport ¶
Transport represents a Transport
func NewTransport ¶
func NewTransport(tripper *transport.RoundTrips, sendData func(ctx context.Context, data []byte), session *Session) *Transport
NewTransport creates a new Transport
func (*Transport) LastRequestID ¶ added in v0.7.3
LastRequestID returns the most recently generated request id without mutating the sequence.