Documentation
¶
Index ¶
- Constants
- Variables
- type ContentTypeValidator
- type DurationValidator
- type HeadersValidator
- type JSONStructureValidator
- type MessageIDValidator
- type PayloadValidator
- type PriorityValidator
- type RetryValidator
- type SchemaValidator
- type SizeValidator
- type ValidationError
- type ValidationResult
- type Validator
- type ValidatorChain
Constants ¶
const ( // DefaultLeaseDuration is the default lease duration when not specified DefaultLeaseDuration = 30 * time.Second // MinLeaseDuration is the minimum lease duration (1 second) MinLeaseDuration = 1 * time.Second )
const ( // MaxHeaderValueSize is the maximum size for a single header value (4KB) MaxHeaderValueSize = 4 * 1024 // MaxTotalHeadersSize is the maximum total size for all headers (32KB) MaxTotalHeadersSize = 32 * 1024 )
const ( // DefaultMinPriority is the minimum allowed priority DefaultMinPriority = 0 // DefaultMaxPriority is the maximum allowed priority DefaultMaxPriority = 100 // DefaultPriority is used when no priority is specified DefaultPriority = 50 )
const ( // DefaultMaxRetryAttempts is the default maximum retry attempts when not specified DefaultMaxRetryAttempts = 3 // InfiniteRetries indicates unlimited retry attempts InfiniteRetries = -1 )
const ( // Default size limits DefaultMaxMessageSize = 150 * 1024 // 150 KB DefaultMaxPayloadSize = 100 * 1024 // 100 KB DefaultMaxMetadataKeySize = 256 // 256 bytes DefaultMaxMetadataValueSize = 4096 // 4 KB DefaultMaxMessageIDSize = 512 // 512 bytes )
Variables ¶
var SupportedContentTypes = map[string]bool{ "application/json": true, "application/x-json": true, "text/plain": true, "application/xml": true, "application/octet-stream": true, "": true, }
SupportedContentTypes defines the MIME types we support
Functions ¶
This section is empty.
Types ¶
type ContentTypeValidator ¶
type ContentTypeValidator struct {
// contains filtered or unexported fields
}
ContentTypeValidator validates message content types
func NewContentTypeValidator ¶
func NewContentTypeValidator(queueMeta *queue_pb.QueueMetadata) *ContentTypeValidator
NewContentTypeValidator creates a new content type validator
func (*ContentTypeValidator) Validate ¶
func (v *ContentTypeValidator) Validate(ctx context.Context, msg *message_pb.Message) *ValidationResult
Validate validates the content type of a message
type DurationValidator ¶
type DurationValidator struct {
// contains filtered or unexported fields
}
DurationValidator validates message duration fields Applies defaults for nil values and validates duration ranges
func (*DurationValidator) Validate ¶
func (v *DurationValidator) Validate(ctx context.Context, msg *message_pb.Message) *ValidationResult
Validate validates the message duration fields Applies defaults for nil values and validates the final values
type HeadersValidator ¶
type HeadersValidator struct {
// contains filtered or unexported fields
}
HeadersValidator validates message headers Ensures headers follow naming conventions and size limits
func (*HeadersValidator) Validate ¶
func (v *HeadersValidator) Validate(ctx context.Context, msg *message_pb.Message) *ValidationResult
Validate validates the message headers
type JSONStructureValidator ¶
type JSONStructureValidator struct{}
JSONStructureValidator validates that JSON payloads have valid structure
func NewJSONStructureValidator ¶
func NewJSONStructureValidator() *JSONStructureValidator
NewJSONStructureValidator creates a new JSON structure validator
func (*JSONStructureValidator) Validate ¶
func (v *JSONStructureValidator) Validate(ctx context.Context, msg *message_pb.Message) *ValidationResult
Validate validates the JSON structure of a message payload
type MessageIDValidator ¶
type MessageIDValidator struct {
// contains filtered or unexported fields
}
MessageIDValidator validates message ID format and constraints This validator ensures message IDs follow ChronoQueue conventions
func (*MessageIDValidator) Validate ¶
func (v *MessageIDValidator) Validate(ctx context.Context, msg *message_pb.Message) *ValidationResult
Validate validates the message ID
type PayloadValidator ¶
type PayloadValidator struct {
// contains filtered or unexported fields
}
PayloadValidator combines multiple validators for comprehensive validation
func NewPayloadValidator ¶
func NewPayloadValidator(queueMeta *queue_pb.QueueMetadata, schemaRegistry schema.Registry) *PayloadValidator
NewPayloadValidator creates a new payload validator with all sub-validators Validation order: 1. Metadata validators (protobuf-defined fields) 2. Payload validators (user content) 3. Schema validators (user payload structure)
func (*PayloadValidator) Validate ¶
func (v *PayloadValidator) Validate(ctx context.Context, msg *message_pb.Message) *ValidationResult
Validate runs all validators
type PriorityValidator ¶
type PriorityValidator struct {
// contains filtered or unexported fields
}
PriorityValidator validates message priority Ensures priority is within configured bounds (queue-specific or global defaults)
func (*PriorityValidator) Validate ¶
func (v *PriorityValidator) Validate(ctx context.Context, msg *message_pb.Message) *ValidationResult
Validate validates the message priority
type RetryValidator ¶
type RetryValidator struct {
// contains filtered or unexported fields
}
RetryValidator validates retry configuration Applies defaults and ensures retry attempts are valid
func (*RetryValidator) Validate ¶
func (v *RetryValidator) Validate(ctx context.Context, msg *message_pb.Message) *ValidationResult
Validate validates the retry configuration Applies defaults for zero values and validates the final value
type SchemaValidator ¶
type SchemaValidator struct {
// contains filtered or unexported fields
}
SchemaValidator validates messages against registered schemas
func NewSchemaValidator ¶
func NewSchemaValidator(registry schema.Registry, queueMeta *queue_pb.QueueMetadata) *SchemaValidator
NewSchemaValidator creates a new schema validator
func (*SchemaValidator) Validate ¶
func (v *SchemaValidator) Validate(ctx context.Context, msg *message_pb.Message) *ValidationResult
Validate validates a message against its schema
type SizeValidator ¶
type SizeValidator struct {
// contains filtered or unexported fields
}
SizeValidator validates message sizes
func NewSizeValidator ¶
func NewSizeValidator(queueMeta *queue_pb.QueueMetadata) *SizeValidator
NewSizeValidator creates a new size validator
func (*SizeValidator) Validate ¶
func (v *SizeValidator) Validate(ctx context.Context, msg *message_pb.Message) *ValidationResult
Validate validates the size of a message
type ValidationError ¶
type ValidationError struct {
Field string
ErrorCode schema_pb.ErrorCode
Message string
Details map[string]string
}
ValidationError provides detailed error information
func NewValidationError ¶
func NewValidationError(field string, code schema_pb.ErrorCode, message string) *ValidationError
NewValidationError creates a new validation error
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface
func (*ValidationError) WithDetail ¶
func (e *ValidationError) WithDetail(key, value string) *ValidationError
WithDetail adds a detail to the validation error
type ValidationResult ¶
type ValidationResult struct {
Valid bool
Errors []*ValidationError
SchemaID string
SchemaVersion int32
}
ValidationResult contains the outcome of validation
func NewValidationResult ¶
func NewValidationResult() *ValidationResult
NewValidationResult creates a new validation result
func (*ValidationResult) AddError ¶
func (r *ValidationResult) AddError(err *ValidationError)
AddError adds an error to the validation result
func (*ValidationResult) HasErrors ¶
func (r *ValidationResult) HasErrors() bool
HasErrors returns true if there are validation errors
func (*ValidationResult) ToProto ¶
func (r *ValidationResult) ToProto() *schema_pb.ValidationResult
ToProto converts ValidationResult to protobuf
type Validator ¶
type Validator interface {
Validate(ctx context.Context, msg *message_pb.Message) *ValidationResult
}
Validator is the interface for message validation
func NewDurationValidator ¶
func NewDurationValidator(queueMeta *queue_pb.QueueMetadata) Validator
NewDurationValidator creates a new duration validator
func NewHeadersValidator ¶
func NewHeadersValidator() Validator
NewHeadersValidator creates a new headers validator
func NewMessageIDValidator ¶
func NewMessageIDValidator() Validator
NewMessageIDValidator creates a new message ID validator
func NewPriorityValidator ¶
func NewPriorityValidator(queueMeta *queue_pb.QueueMetadata) Validator
NewPriorityValidator creates a new priority validator
func NewRetryValidator ¶
func NewRetryValidator(queueMeta *queue_pb.QueueMetadata) Validator
NewRetryValidator creates a new retry validator
type ValidatorChain ¶
type ValidatorChain struct {
// contains filtered or unexported fields
}
ValidatorChain chains multiple validators
func NewValidatorChain ¶
func NewValidatorChain(validators ...Validator) *ValidatorChain
NewValidatorChain creates a new validator chain
func (*ValidatorChain) Validate ¶
func (c *ValidatorChain) Validate(ctx context.Context, msg *message_pb.Message) *ValidationResult
Validate runs all validators in the chain