Documentation
¶
Overview ¶
Package types defines shared message types for WebSocket communication
Index ¶
Constants ¶
const ( // Client errors (4xx equivalent) ErrorCodeValidation = "VALIDATION_ERROR" ErrorCodeInvalidAction = "INVALID_ACTION" ErrorCodeNotFound = "NOT_FOUND" ErrorCodeForbidden = "FORBIDDEN" ErrorCodeRateLimited = "RATE_LIMITED" ErrorCodeDuplicateRequest = "DUPLICATE_REQUEST" // Server errors (5xx equivalent) ErrorCodeInternal = "INTERNAL_ERROR" ErrorCodeTimeout = "TIMEOUT" ErrorCodeStorageError = "STORAGE_ERROR" ErrorCodeProcessingFailed = "PROCESSING_FAILED" // Connection errors ErrorCodeConnectionClosed = "CONNECTION_CLOSED" ErrorCodeInvalidMessage = "INVALID_MESSAGE" ErrorCodeProtocolError = "PROTOCOL_ERROR" )
Standard error codes
Variables ¶
This section is empty.
Functions ¶
func IsClientError ¶
IsClientError checks if the error code represents a client error
func IsRetryableError ¶
IsRetryableError checks if an error code indicates a retryable condition
func IsServerError ¶
IsServerError checks if the error code represents a server error
Types ¶
type AcknowledgmentMessage ¶
type AcknowledgmentMessage struct {
Message
RequestID string `json:"request_id"`
Status string `json:"status"` // "queued", "processing"
Text string `json:"message,omitempty"`
}
AcknowledgmentMessage is sent for async requests
func NewAcknowledgmentMessage ¶
func NewAcknowledgmentMessage(requestID, status, message string) *AcknowledgmentMessage
NewAcknowledgmentMessage creates a new acknowledgment message
type ErrorInfo ¶
type ErrorInfo struct {
Code string `json:"code"`
Message string `json:"message"`
Details map[string]interface{} `json:"details,omitempty"`
Retry *RetryInfo `json:"retry,omitempty"`
}
ErrorInfo contains structured error information
func NewErrorInfo ¶
NewErrorInfo creates a new error info structure
func (*ErrorInfo) WithDetail ¶
WithDetail adds a detail to the error info
type ErrorMessage ¶
type ErrorMessage struct {
Message
RequestID string `json:"request_id,omitempty"`
Error *ErrorInfo `json:"error"`
}
ErrorMessage represents an error response
func NewErrorMessage ¶
func NewErrorMessage(requestID string, errorInfo *ErrorInfo) *ErrorMessage
NewErrorMessage creates a new error message
type Message ¶
type Message struct {
Type MessageType `json:"type"`
ID string `json:"id,omitempty"`
Timestamp int64 `json:"timestamp"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
Message is the base structure for all WebSocket messages
func NewMessage ¶
func NewMessage(msgType MessageType) Message
NewMessage creates a base message with timestamp
type MessageType ¶
type MessageType string
MessageType defines the type of WebSocket message
const ( // Request message types MessageTypeRequest MessageType = "request" // Response message types MessageTypeResponse MessageType = "response" MessageTypeAcknowledgment MessageType = "acknowledgment" MessageTypeProgress MessageType = "progress" MessageTypeError MessageType = "error" // Control message types MessageTypePing MessageType = "ping" MessageTypePong MessageType = "pong" )
type ProgressMessage ¶
type ProgressMessage struct {
Message
RequestID string `json:"request_id"`
Percentage float64 `json:"percentage"` // 0-100
Text string `json:"message,omitempty"`
Details map[string]interface{} `json:"details,omitempty"`
}
ProgressMessage represents async processing progress
func NewProgressMessage ¶
func NewProgressMessage(requestID string, percentage float64, message string) *ProgressMessage
NewProgressMessage creates a new progress message
type RequestMessage ¶
type RequestMessage struct {
Message
Action string `json:"action"`
Payload map[string]interface{} `json:"payload,omitempty"`
}
RequestMessage represents an incoming WebSocket request
func NewRequestMessage ¶
func NewRequestMessage(action string, payload map[string]interface{}) *RequestMessage
NewRequestMessage creates a new request message
type ResponseMessage ¶
type ResponseMessage struct {
Message
RequestID string `json:"request_id"`
Success bool `json:"success"`
Data interface{} `json:"data,omitempty"`
Error *ErrorInfo `json:"error,omitempty"`
}
ResponseMessage represents a synchronous response
func NewResponseMessage ¶
func NewResponseMessage(requestID string, success bool, data interface{}) *ResponseMessage
NewResponseMessage creates a new response message