Documentation
¶
Index ¶
- func CreateTestLogger(level slog.Level) *slog.Logger
- func GetOAuthToken(ctx context.Context, oauthURL, clientID, clientSecret string) (string, error)
- func GetTestToken(ctx context.Context, config *TestConfig) (string, error)
- type EventClient
- type EventClientImpl
- func (e *EventClientImpl) AddHandler(expr string, handler func(Message)) error
- func (e *EventClientImpl) ListHandlers() []string
- func (e *EventClientImpl) LogHandlerState()
- func (e *EventClientImpl) NewAggregateSubscription(ctx context.Context, topic string, aggregateType string, aggregateID int, ...) error
- func (e *EventClientImpl) NewAggregateTypeSubscription(ctx context.Context, topic string, aggregateType string, isRegex bool) error
- func (e *EventClientImpl) NewSubscription(ctx context.Context, topic string) error
- func (e *EventClientImpl) NewSubscriptionWithOptions(ctx context.Context, topic string, aggregateType string, aggregateID *int, ...) error
- func (e *EventClientImpl) Publish(topic string, v interface{}) error
- func (e *EventClientImpl) PublishViaAPI(ctx context.Context, topic string, v interface{}, aggregateType string, ...) error
- func (e *EventClientImpl) PublishWithAggregate(topic string, v interface{}, aggregateType string, aggregateID *int) error
- func (e *EventClientImpl) RegisterSubscriber() error
- func (e *EventClientImpl) RequestSession() error
- func (e *EventClientImpl) Start() error
- func (e *EventClientImpl) Stop() error
- type EventClientOptions
- type GetTokenCallback
- type KeyValuePair
- type Message
- type MessageContent
- func (mc *MessageContent) AsMap() (map[string]string, bool)
- func (mc *MessageContent) AsString() string
- func (mc *MessageContent) GetValue(key string) string
- func (mc *MessageContent) IsMap() bool
- func (mc *MessageContent) IsString() bool
- func (mc MessageContent) MarshalJSON() ([]byte, error)
- func (mc *MessageContent) String() string
- func (mc *MessageContent) UnmarshalJSON(data []byte) error
- type MessageCreate
- type OAuthToken
- type Session
- type SessionCreate
- type Subscriber
- type Subscription
- type SubscriptionCreate
- type TestConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTestLogger ¶ added in v1.0.0
CreateTestLogger creates a logger for testing
func GetOAuthToken ¶ added in v1.0.0
GetOAuthToken is a public convenience function for obtaining OAuth tokens
func GetTestToken ¶ added in v1.0.0
func GetTestToken(ctx context.Context, config *TestConfig) (string, error)
GetTestToken fetches an OAuth token for testing
Types ¶
type EventClient ¶
type EventClient interface {
Start() error
Stop() error
AddHandler(expr string, handler func(Message)) error
Publish(topic string, v interface{}) error
PublishWithAggregate(topic string, v interface{}, aggregateType string, aggregateID *int) error
PublishViaAPI(ctx context.Context, topic string, v interface{}, aggregateType string, aggregateID *int) error
NewSubscription(ctx context.Context, topic string) error
NewSubscriptionWithOptions(ctx context.Context, topic string, aggregateType string, aggregateID *int, isRegex bool) error
NewAggregateTypeSubscription(ctx context.Context, topic string, aggregateType string, isRegex bool) error
NewAggregateSubscription(ctx context.Context, topic string, aggregateType string, aggregateID int, isRegex bool) error
}
func CreateTestClient ¶ added in v1.0.0
func CreateTestClient(ctx context.Context, config *TestConfig) (EventClient, error)
CreateTestClient creates a test client with proper configuration
func NewEventClient ¶
func NewEventClient(ctx context.Context, options EventClientOptions, getTokenCallback GetTokenCallback, logger *slog.Logger) EventClient
type EventClientImpl ¶
type EventClientImpl struct {
Ctx context.Context
Options EventClientOptions
GetTokenCallback GetTokenCallback
Logger *slog.Logger
HTTPClient *http.Client
// internal values set during runtime
Subscriber *Subscriber
Session *Session
ConnectionID string
// contains filtered or unexported fields
}
func (*EventClientImpl) AddHandler ¶
func (e *EventClientImpl) AddHandler(expr string, handler func(Message)) error
AddHandler registers a callback for topics matching the given regex The expr should be a valid Go regex (e.g. "^user\\..*$" to match "user.*").
func (*EventClientImpl) ListHandlers ¶ added in v1.3.2
func (e *EventClientImpl) ListHandlers() []string
ListHandlers returns information about currently registered handlers (for debugging)
func (*EventClientImpl) LogHandlerState ¶ added in v1.3.2
func (e *EventClientImpl) LogHandlerState()
LogHandlerState logs the current state of all handlers (for debugging)
func (*EventClientImpl) NewAggregateSubscription ¶ added in v1.0.0
func (e *EventClientImpl) NewAggregateSubscription(ctx context.Context, topic string, aggregateType string, aggregateID int, isRegex bool) error
NewAggregateSubscription creates a subscription for a specific aggregate type and ID
func (*EventClientImpl) NewAggregateTypeSubscription ¶ added in v1.0.0
func (e *EventClientImpl) NewAggregateTypeSubscription(ctx context.Context, topic string, aggregateType string, isRegex bool) error
NewAggregateTypeSubscription creates a subscription for all messages of a specific aggregate type
func (*EventClientImpl) NewSubscription ¶
func (e *EventClientImpl) NewSubscription(ctx context.Context, topic string) error
func (*EventClientImpl) NewSubscriptionWithOptions ¶ added in v1.0.0
func (*EventClientImpl) Publish ¶
func (e *EventClientImpl) Publish(topic string, v interface{}) error
Publish sends a topic and payload. It blocks only if the send buffer is full.
func (*EventClientImpl) PublishViaAPI ¶ added in v1.0.0
func (e *EventClientImpl) PublishViaAPI(ctx context.Context, topic string, v interface{}, aggregateType string, aggregateID *int) error
PublishViaAPI publishes a message via HTTP API instead of WebSocket (useful for testing)
func (*EventClientImpl) PublishWithAggregate ¶ added in v1.0.0
func (e *EventClientImpl) PublishWithAggregate(topic string, v interface{}, aggregateType string, aggregateID *int) error
PublishWithAggregate sends a topic and payload with aggregate information
func (*EventClientImpl) RegisterSubscriber ¶
func (e *EventClientImpl) RegisterSubscriber() error
func (*EventClientImpl) RequestSession ¶
func (e *EventClientImpl) RequestSession() error
func (*EventClientImpl) Start ¶
func (e *EventClientImpl) Start() error
func (*EventClientImpl) Stop ¶
func (e *EventClientImpl) Stop() error
type EventClientOptions ¶
type EventClientOptions struct {
EventAPIURL string
SocketsURL string
PingInterval int
MaxReconnectAttempts int // Maximum number of reconnection attempts (0 = infinite)
ReconnectBackoff time.Duration // Initial backoff duration between reconnection attempts
MaxReconnectBackoff time.Duration // Maximum backoff duration
}
type KeyValuePair ¶ added in v1.3.0
type KeyValuePair struct {
Key string `json:"Key"`
Value interface{} `json:"Value"`
}
KeyValuePair represents a key-value pair from the server
type Message ¶
type Message struct {
ID string `json:"id"`
CreatedAt string `json:"created_at"`
Topic string `json:"topic"`
Content MessageContent `json:"content"`
SubscriberID string `json:"subscriber_id"`
ConnectionID string `json:"connection_id"`
SessionID string `json:"session_id"`
Timestamp string `json:"timestamp"`
Priority string `json:"priority,omitempty"`
AggregateType string `json:"aggregate_type,omitempty"`
AggregateID *int `json:"aggregate_id,omitempty"`
}
type MessageContent ¶ added in v1.3.0
type MessageContent struct {
// contains filtered or unexported fields
}
MessageContent represents flexible content that can be either a string or key-value pairs
func NewMessageContentFromMap ¶ added in v1.3.0
func NewMessageContentFromMap(content map[string]string) MessageContent
NewMessageContentFromMap creates a MessageContent from a map
func NewMessageContentFromString ¶ added in v1.3.0
func NewMessageContentFromString(content string) MessageContent
NewMessageContentFromString creates a MessageContent from a string
func (*MessageContent) AsMap ¶ added in v1.3.0
func (mc *MessageContent) AsMap() (map[string]string, bool)
AsMap returns the content as a map if it was parsed from key-value pairs
func (*MessageContent) AsString ¶ added in v1.3.0
func (mc *MessageContent) AsString() string
AsString returns the content as a string (same as String() but more explicit)
func (*MessageContent) GetValue ¶ added in v1.3.0
func (mc *MessageContent) GetValue(key string) string
GetValue gets a value by key if content is a map, otherwise returns empty string
func (*MessageContent) IsMap ¶ added in v1.3.0
func (mc *MessageContent) IsMap() bool
IsMap returns true if the content was parsed as key-value pairs
func (*MessageContent) IsString ¶ added in v1.3.0
func (mc *MessageContent) IsString() bool
IsString returns true if the content is a simple string
func (MessageContent) MarshalJSON ¶ added in v1.3.0
func (mc MessageContent) MarshalJSON() ([]byte, error)
MarshalJSON implements custom marshaling for MessageContent
func (*MessageContent) String ¶ added in v1.3.0
func (mc *MessageContent) String() string
String returns the content as a string
func (*MessageContent) UnmarshalJSON ¶ added in v1.3.0
func (mc *MessageContent) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom unmarshaling for MessageContent
type MessageCreate ¶
type OAuthToken ¶ added in v1.0.0
type OAuthToken struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
}
OAuthToken represents an OAuth token response
type SessionCreate ¶ added in v1.2.0
type SessionCreate struct {
SubscriberID string `json:"subscriber_id"`
}
type Subscriber ¶
type Subscription ¶
type Subscription struct {
ID string `json:"id"`
CreatedAt string `json:"created_at"`
Topic string `json:"topic"`
SubscriberID string `json:"subscriber_id"`
AggregateType string `json:"aggregate_type,omitempty"`
AggregateID *int `json:"aggregate_id,omitempty"`
IsRegex bool `json:"is_regex,omitempty"`
}
type SubscriptionCreate ¶
type TestConfig ¶ added in v1.0.0
type TestConfig struct {
OAuthClientID string
OAuthClientSecret string
OAuthTokenURL string
EventAPIURL string
SocketsURL string
TestTimeout time.Duration
LogLevel slog.Level
}
TestConfig holds configuration for tests
func LoadTestConfig ¶ added in v1.0.0
func LoadTestConfig() (*TestConfig, error)
LoadTestConfig loads test configuration from environment variables