Documentation
¶
Index ¶
- Constants
- Variables
- func Bind(app *runtime.App, publisher Publisher) error
- func Broadcast(ctx context.Context, action string, data any) error
- func ClearDefaultPublisher(publisher Publisher)
- func PublishToUser(ctx context.Context, userID string, action string, data any) error
- func PushRoom(ctx context.Context, roomID string, action string, data any) error
- func PushUser(ctx context.Context, userID string, action string, data any) error
- func SetDefaultPublisher(publisher Publisher)
- func ValidatePublisherConfig(cfg PublisherConfig) error
- type ActionCodec
- type ActionContext
- func (a *ActionContext) Abort()
- func (a *ActionContext) ActionError(code string, message string, err error) error
- func (a *ActionContext) Bind(v any) error
- func (a *ActionContext) ClientID() string
- func (a *ActionContext) Context() context.Context
- func (a *ActionContext) Control(event string, data any) error
- func (a *ActionContext) Get(key string) any
- func (a *ActionContext) IsAborted() bool
- func (a *ActionContext) Next() error
- func (a *ActionContext) PushRoom(roomID string, evt *Event) error
- func (a *ActionContext) PushUser(userID string, evt *Event) error
- func (a *ActionContext) Reply(action string, data any) error
- func (a *ActionContext) RunHandlers(handlers ...HandlerFunc) error
- func (a *ActionContext) Set(key string, value any)
- func (a *ActionContext) SetContext(ctx context.Context)
- func (a *ActionContext) SetHandlers(handlers ...HandlerFunc)
- func (a *ActionContext) ShouldBindJSON(dst any) error
- func (a *ActionContext) UserID() string
- type ActionError
- type ActionHandlerFunc
- type ActionMessage
- type AllowAnonymousAuthenticator
- type AuthOptions
- type AuthResult
- type Authenticator
- type Client
- type Config
- type Context
- type Dispatcher
- type Event
- type EventWriter
- type Gateway
- type HandlerFunc
- type Identity
- type IdentityKind
- type IdentityState
- type Lifecycle
- type Logger
- type MiddlewareFunc
- type Option
- type Options
- type Presence
- type Publisher
- type PublisherConfig
- type Registry
- type Room
- type Route
- type Router
- type Runner
- type ServerOptions
- type Service
- type Target
Constants ¶
View Source
const ( TargetUser = "user" TargetRoom = "room" TargetBroadcast = "broadcast" )
View Source
const DefaultTopic = "rt:events"
View Source
const KeyRealtime runtime.Key = "realtime"
Variables ¶
View Source
var ( ErrNilClient = errors.New("realtime: nil client") ErrEmptyClientID = errors.New("realtime: empty client id") ErrEmptyEvent = errors.New("realtime: empty event") ErrNilPublisher = errors.New("realtime: nil publisher") ErrNilGateway = errors.New("realtime: nil gateway") ErrNilSubscriber = errors.New("realtime: nil subscriber") ErrNilRouter = errors.New("realtime: nil router") ErrNilActionCodec = errors.New("realtime: nil action codec") ErrNilActionHandler = errors.New("realtime: nil action handler") ErrEmptyAction = errors.New("realtime: empty action") ErrEmptyIdentity = errors.New("realtime: empty identity") ErrClientNotFound = errors.New("realtime: client not found") ErrClientBufferFull = errors.New("realtime: client buffer full") ErrActionAlreadyRegistered = errors.New("realtime: action already registered") ErrActionNotFound = errors.New("realtime: action not found") ErrInvalidAction = errors.New("realtime: invalid action") ErrDefaultNotReady = errors.New("realtime: default not initialized") ErrUnsupportedTopic = errors.New("realtime: unsupported topic") ErrClosed = errors.New("realtime: closed") )
Functions ¶
func ClearDefaultPublisher ¶
func ClearDefaultPublisher(publisher Publisher)
func PublishToUser ¶
func SetDefaultPublisher ¶
func SetDefaultPublisher(publisher Publisher)
func ValidatePublisherConfig ¶
func ValidatePublisherConfig(cfg PublisherConfig) error
Types ¶
type ActionCodec ¶
type ActionCodec interface {
DecodeAction(payload []byte) (ActionMessage, error)
EncodeAction(message ActionMessage) ([]byte, error)
}
type ActionContext ¶
type ActionContext struct {
Client *Client
Identity *Identity
Event *Event
Gateway Gateway
Values map[string]any
Message ActionMessage
Raw []byte
// contains filtered or unexported fields
}
func (*ActionContext) Abort ¶
func (a *ActionContext) Abort()
func (*ActionContext) ActionError ¶
func (a *ActionContext) ActionError(code string, message string, err error) error
func (*ActionContext) Bind ¶
func (a *ActionContext) Bind(v any) error
func (*ActionContext) ClientID ¶
func (a *ActionContext) ClientID() string
func (*ActionContext) Context ¶
func (a *ActionContext) Context() context.Context
func (*ActionContext) Get ¶
func (a *ActionContext) Get(key string) any
func (*ActionContext) IsAborted ¶
func (a *ActionContext) IsAborted() bool
func (*ActionContext) Next ¶
func (a *ActionContext) Next() error
func (*ActionContext) RunHandlers ¶
func (a *ActionContext) RunHandlers(handlers ...HandlerFunc) error
func (*ActionContext) Set ¶
func (a *ActionContext) Set(key string, value any)
func (*ActionContext) SetContext ¶
func (a *ActionContext) SetContext(ctx context.Context)
func (*ActionContext) SetHandlers ¶
func (a *ActionContext) SetHandlers(handlers ...HandlerFunc)
func (*ActionContext) ShouldBindJSON ¶
func (a *ActionContext) ShouldBindJSON(dst any) error
func (*ActionContext) UserID ¶
func (a *ActionContext) UserID() string
type ActionError ¶
func NewActionError ¶
func NewActionError(code string, message string, err error) *ActionError
func (*ActionError) Error ¶
func (e *ActionError) Error() string
func (*ActionError) Unwrap ¶
func (e *ActionError) Unwrap() error
type ActionHandlerFunc ¶
type ActionHandlerFunc = HandlerFunc
type ActionMessage ¶
type AllowAnonymousAuthenticator ¶
type AllowAnonymousAuthenticator struct{}
func (AllowAnonymousAuthenticator) Authenticate ¶
func (AllowAnonymousAuthenticator) Authenticate(_ context.Context, _ *http.Request) (*AuthResult, error)
type AuthOptions ¶
type AuthResult ¶
func (*AuthResult) Identity ¶
func (r *AuthResult) Identity() *Identity
type Authenticator ¶
type Client ¶
type Client struct {
ID string
Identity *Identity
Metadata map[string]any
UserID string
TenantID int64
Events map[string]bool
Ch chan Event
CreatedAt time.Time
LastActiveAt time.Time
}
func (*Client) Authenticated ¶
func (*Client) CurrentIdentity ¶
func (*Client) IdentityState ¶
func (c *Client) IdentityState() IdentityState
func (*Client) Subscribed ¶
type Config ¶
func DefaultConfig ¶
func DefaultConfig() Config
type Context ¶
type Context = ActionContext
type Dispatcher ¶
type Dispatcher interface {
DispatchEvent(ctx context.Context, evt *Event) error
DispatchLocal(ctx context.Context, evt *Event) error
DispatchClient(ctx context.Context, clientID string, evt *Event) error
PushUser(ctx context.Context, userID string, evt *Event) error
PushClient(ctx context.Context, clientID string, evt *Event) error
PushRoom(ctx context.Context, roomID string, evt *Event) error
Broadcast(ctx context.Context, evt *Event) error
}
type Event ¶
type Event struct {
Action string `json:"action"`
RequestID string `json:"request_id,omitempty"`
TraceID string `json:"trace_id,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Data any `json:"data,omitempty"`
Event string `json:"event,omitempty"`
Module string `json:"module,omitempty"`
Target *Target `json:"target,omitempty"`
TenantID int64 `json:"tenant_id,omitempty"`
RoomID string `json:"room_id,omitempty"`
Payload json.RawMessage `json:"payload,omitempty"`
Time int64 `json:"time,omitempty"`
}
type Gateway ¶
type Gateway interface {
Handle(ctx *ActionContext) error
Publish(ctx context.Context, evt *Event) error
PushUser(ctx context.Context, userID string, evt *Event) error
PushClient(ctx context.Context, clientID string, evt *Event) error
PushRoom(ctx context.Context, roomID string, evt *Event) error
Broadcast(ctx context.Context, evt *Event) error
}
type HandlerFunc ¶
type HandlerFunc func(action *ActionContext) error
type Identity ¶
type Identity struct {
ID string `json:"id"`
Type string `json:"type,omitempty"`
DeviceID string `json:"device_id,omitempty"`
Platform string `json:"platform,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
TenantID int64 `json:"-"`
Kind IdentityKind `json:"-"`
Subject string `json:"-"`
}
func IdentityFromAuthResult ¶
func IdentityFromAuthResult(result *AuthResult) *Identity
func NewUserIdentity ¶
func (*Identity) Authenticated ¶
func (*Identity) State ¶
func (i *Identity) State() IdentityState
type IdentityKind ¶
type IdentityKind string
const ( IdentityKindUser IdentityKind = "user" IdentityKindDevice IdentityKind = "device" )
type IdentityState ¶
type IdentityState string
const ( IdentityStateAnonymous IdentityState = "anonymous" IdentityStateAuthenticated IdentityState = "authenticated" )
type MiddlewareFunc ¶
type MiddlewareFunc func(HandlerFunc) HandlerFunc
type Options ¶
func NewOptions ¶
type Publisher ¶
type Publisher interface {
PushUser(ctx context.Context, userID string, evt *Event) error
PushRoom(ctx context.Context, roomID string, evt *Event) error
Broadcast(ctx context.Context, evt *Event) error
}
func DefaultPublisher ¶
func DefaultPublisher() Publisher
func NewConfiguredPublisher ¶
func NewConfiguredPublisher(cfg PublisherConfig, logName string) (Publisher, string, error)
type PublisherConfig ¶
type PublisherConfig struct {
Driver string `mapstructure:"driver" yaml:"driver"`
Addr string `mapstructure:"addr" yaml:"addr"`
Topic string `mapstructure:"topic" yaml:"topic"`
TopicPrefix string `mapstructure:"topic_prefix" yaml:"topic_prefix"`
SubjectPrefix string `mapstructure:"subject_prefix" yaml:"subject_prefix"`
NodeName string `mapstructure:"node_name" yaml:"node_name"`
StreamMaxLen int64 `mapstructure:"stream_max_len" yaml:"stream_max_len"`
}
type Route ¶
type Route struct {
Action string
Middleware []MiddlewareFunc
Handler HandlerFunc
Compiled HandlerFunc
Handlers []HandlerFunc
}
type Router ¶
type Router interface {
Use(middleware ...MiddlewareFunc)
On(action string, handlers ...HandlerFunc)
Group(prefix string, middleware ...MiddlewareFunc) Router
Match(action string) (*Route, bool)
}
type ServerOptions ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.