Documentation
¶
Index ¶
- Constants
- type AcknowledgmentMessage
- type ErrorData
- type ErrorMessage
- type IncomingMessage
- type MessageType
- type OutgoingMessage
- type PayloadValidator
- func (pv *PayloadValidator) RequireFields(payload json.RawMessage, fields ...string) error
- func (pv *PayloadValidator) ValidateNumber(data map[string]interface{}, field string, min, max float64) error
- func (pv *PayloadValidator) ValidateString(data map[string]interface{}, field string, minLen, maxLen int) error
- type ProgressMessage
- type ResponseMessage
- type ValidateHandler
- type ValidationError
- type ValidationErrors
Constants ¶
const ( // Incoming message types MessageTypeRequest = "request" // Outgoing message types MessageTypeResponse = "response" MessageTypeAcknowledgment = "acknowledgment" MessageTypeProgress = "progress" MessageTypeError = "error" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AcknowledgmentMessage ¶
type AcknowledgmentMessage struct {
OutgoingMessage
Status string `json:"status"`
Message string `json:"message"`
}
AcknowledgmentMessage represents an acknowledgment of an async request
func NewAcknowledgmentMessage ¶
func NewAcknowledgmentMessage(requestID, status, message string) *AcknowledgmentMessage
NewAcknowledgmentMessage creates a new acknowledgment message
type ErrorData ¶
type ErrorData struct {
Code string `json:"code"`
Message string `json:"message"`
Details map[string]interface{} `json:"details,omitempty"`
}
ErrorData contains error details
type ErrorMessage ¶
type ErrorMessage struct {
OutgoingMessage
Error *ErrorData `json:"error"`
}
ErrorMessage represents an error message
func NewErrorMessage ¶
func NewErrorMessage(err *ErrorData) *ErrorMessage
NewErrorMessage creates a new error message
type IncomingMessage ¶
type IncomingMessage struct {
Type MessageType `json:"type"`
ID string `json:"id,omitempty"`
Action string `json:"action"`
Payload json.RawMessage `json:"payload,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
IncomingMessage represents a message received from a WebSocket client
func ValidateIncomingMessage ¶
func ValidateIncomingMessage(data []byte) (*IncomingMessage, error)
ValidateIncomingMessage validates an incoming WebSocket message
type OutgoingMessage ¶
type OutgoingMessage struct {
Type MessageType `json:"type"`
RequestID string `json:"request_id,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
OutgoingMessage represents a message sent to a WebSocket client
type PayloadValidator ¶
type PayloadValidator struct{}
PayloadValidator provides common payload validation functions
func (*PayloadValidator) RequireFields ¶
func (pv *PayloadValidator) RequireFields(payload json.RawMessage, fields ...string) error
RequireFields checks that required fields exist in the payload
func (*PayloadValidator) ValidateNumber ¶
func (pv *PayloadValidator) ValidateNumber(data map[string]interface{}, field string, min, max float64) error
ValidateNumber validates a numeric field
func (*PayloadValidator) ValidateString ¶
func (pv *PayloadValidator) ValidateString(data map[string]interface{}, field string, minLen, maxLen int) error
ValidateString validates a string field
type ProgressMessage ¶
type ProgressMessage struct {
OutgoingMessage
Percentage float64 `json:"percentage"`
Message string `json:"message"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
ProgressMessage represents a progress update for an async operation
func NewProgressMessage ¶
func NewProgressMessage(requestID string, percentage float64, message string) *ProgressMessage
NewProgressMessage creates a new progress message
type ResponseMessage ¶
type ResponseMessage struct {
OutgoingMessage
Success bool `json:"success"`
Data interface{} `json:"data,omitempty"`
Error *ErrorData `json:"error,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
ResponseMessage represents a response to a request
func NewResponseMessage ¶
func NewResponseMessage(requestID string, success bool, data interface{}, err *ErrorData) *ResponseMessage
NewResponseMessage creates a new response message
type ValidateHandler ¶
type ValidateHandler interface {
ValidatePayload(payload json.RawMessage) error
}
ValidateHandler provides validation for specific handler payloads
type ValidationError ¶
ValidationError represents a validation error
type ValidationErrors ¶
type ValidationErrors []ValidationError
ValidationErrors represents multiple validation errors
func (ValidationErrors) Error ¶
func (ve ValidationErrors) Error() string
Error implements the error interface