Documentation
¶
Index ¶
- Variables
- type HandlerOption
- func WithBlockOnFullBuffer() HandlerOption
- func WithOriginPatterns(patterns ...string) HandlerOption
- func WithPingInterval(interval time.Duration) HandlerOption
- func WithSendBuffer(size int) HandlerOption
- func WithSlowWriteThreshold(threshold time.Duration) HandlerOption
- func WithStatsInterval(interval time.Duration) HandlerOption
- func WithWriteTimeout(timeout time.Duration) HandlerOption
- type IndexedScope
- func (s IndexedScope[T]) Address(id string) (string, error)
- func (s IndexedScope[T]) Define(manager *Manager, id string, initial T, opts ...KeyOption) (*Key[T], error)
- func (s IndexedScope[T]) Lookup(manager *Manager, id string) (*Key[T], error)
- func (s IndexedScope[T]) MustAddress(id string) string
- func (s IndexedScope[T]) Name() string
- func (s IndexedScope[T]) Wildcard() string
- type Key
- func Define[T any](manager *Manager, name string, initial T, opts ...KeyOption) (*Key[T], error)
- func DefineIndexed[T any](manager *Manager, scopeName, id string, initial T, opts ...KeyOption) (*Key[T], error)
- func DefineSingleton[T any](manager *Manager, name string, initial T, opts ...KeyOption) (*Key[T], error)
- func Lookup[T any](manager *Manager, name string) (*Key[T], error)
- func LookupIndexed[T any](manager *Manager, scopeName, id string) (*Key[T], error)
- func LookupSingleton[T any](manager *Manager, name string) (*Key[T], error)
- func (k *Key[T]) Lock(ctx context.Context) (*Locked[T], error)
- func (k *Key[T]) Name() string
- func (k *Key[T]) Set(ctx context.Context, value T, opts ...WriteOption) error
- func (k *Key[T]) Snapshot(ctx context.Context) (T, Meta, error)
- func (k *Key[T]) Update(ctx context.Context, update func(*T), opts ...WriteOption) error
- type KeyOption
- type Locked
- type LogLevel
- type Logger
- type Manager
- type Message
- type MessageType
- type Meta
- type Option
- type PatchOperation
- type SingletonScope
- type WriteOption
Constants ¶
This section is empty.
Variables ¶
var ( ErrAlreadyDefined = errors.New("syncedstate: state name already defined") ErrClosed = errors.New("syncedstate: locked state already closed") ErrInvalidScope = errors.New("syncedstate: invalid state scope") ErrMissingValue = errors.New("syncedstate: message value is required") ErrNotFound = errors.New("syncedstate: state name not found") ErrTypeMismatch = errors.New("syncedstate: state type mismatch") ErrVersionConflict = errors.New("syncedstate: state version conflict") ErrWildcardName = errors.New("syncedstate: wildcard state name requires an exact indexed state name") )
Functions ¶
This section is empty.
Types ¶
type HandlerOption ¶
type HandlerOption func(*handlerConfig)
func WithBlockOnFullBuffer ¶
func WithBlockOnFullBuffer() HandlerOption
func WithOriginPatterns ¶
func WithOriginPatterns(patterns ...string) HandlerOption
func WithPingInterval ¶
func WithPingInterval(interval time.Duration) HandlerOption
WithPingInterval enables server-side keepalive: the handler pings each client on a ticker and closes the connection if a pong is not received within the interval. This surfaces half-open / silently-dropped links (laptop sleep, NAT idle-reap) as a real close event so the client can reconnect. Zero (the default) disables keepalive.
func WithSendBuffer ¶
func WithSendBuffer(size int) HandlerOption
func WithSlowWriteThreshold ¶
func WithSlowWriteThreshold(threshold time.Duration) HandlerOption
WithSlowWriteThreshold sets the write duration above which a frame counts as a slow write in client stats. The default is 250ms.
func WithStatsInterval ¶
func WithStatsInterval(interval time.Duration) HandlerOption
WithStatsInterval logs a "client stats" record per connection on this interval: messages and bytes written, send-queue depth and high-water mark, the longest queue wait and write, and slow-write counts. Zero (the default) disables the report.
func WithWriteTimeout ¶
func WithWriteTimeout(timeout time.Duration) HandlerOption
type IndexedScope ¶
type IndexedScope[T any] struct { // contains filtered or unexported fields }
func MustIndexedScope ¶
func MustIndexedScope[T any](name string) IndexedScope[T]
func NewIndexedScope ¶
func NewIndexedScope[T any](name string) (IndexedScope[T], error)
func (IndexedScope[T]) Lookup ¶
func (s IndexedScope[T]) Lookup(manager *Manager, id string) (*Key[T], error)
func (IndexedScope[T]) MustAddress ¶
func (s IndexedScope[T]) MustAddress(id string) string
func (IndexedScope[T]) Name ¶
func (s IndexedScope[T]) Name() string
func (IndexedScope[T]) Wildcard ¶
func (s IndexedScope[T]) Wildcard() string
type Key ¶
type Key[T any] struct { // contains filtered or unexported fields }
func DefineIndexed ¶
func DefineSingleton ¶
func LookupIndexed ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func (*Manager) BufferFullEvents ¶
BufferFullEvents returns how many client connections were closed because their send buffer overflowed since the manager was created.
type Message ¶
type Message struct {
Type MessageType `json:"type"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Version uint64 `json:"version,omitempty"`
Value json.RawMessage `json:"value,omitempty"`
Error string `json:"error,omitempty"`
BaseVersion uint64 `json:"baseVersion,omitempty"`
Patch []PatchOperation `json:"patch,omitempty"`
SyncMode string `json:"syncMode,omitempty"`
SubscriptionID string `json:"subscriptionId,omitempty"`
}
func (Message) MarshalJSON ¶
type MessageType ¶
type MessageType string
const ( MessageSubscribe MessageType = "subscribe" MessageUnsubscribe MessageType = "unsubscribe" MessageSet MessageType = "set" MessagePatch MessageType = "patch" MessageSnapshot MessageType = "snapshot" MessageUpdate MessageType = "update" MessageLog MessageType = "log" MessageError MessageType = "error" )
type PatchOperation ¶
type PatchOperation struct {
Op string `json:"op"`
Path string `json:"path"`
Value json.RawMessage `json:"value,omitempty"`
}
PatchOperation is an object-field JSON Patch operation. Arrays are atomic values.
func (*PatchOperation) UnmarshalJSON ¶
func (op *PatchOperation) UnmarshalJSON(raw []byte) error
type SingletonScope ¶
type SingletonScope[T any] struct { // contains filtered or unexported fields }
func MustSingletonScope ¶
func MustSingletonScope[T any](name string) SingletonScope[T]
func NewSingletonScope ¶
func NewSingletonScope[T any](name string) (SingletonScope[T], error)
func (SingletonScope[T]) Address ¶
func (s SingletonScope[T]) Address() string
func (SingletonScope[T]) Define ¶
func (s SingletonScope[T]) Define(manager *Manager, initial T, opts ...KeyOption) (*Key[T], error)
func (SingletonScope[T]) Lookup ¶
func (s SingletonScope[T]) Lookup(manager *Manager) (*Key[T], error)
func (SingletonScope[T]) Name ¶
func (s SingletonScope[T]) Name() string
type WriteOption ¶
type WriteOption func(*writeConfig)
func WithVersion ¶
func WithVersion(version uint64) WriteOption