Documentation
¶
Index ¶
- Variables
- type ErrorCode
- type Schema
- func (*Schema) Descriptor() ([]byte, []int)deprecated
- func (x *Schema) GetContent() string
- func (x *Schema) GetContentType() string
- func (x *Schema) GetCreatedAt() int64
- func (x *Schema) GetDescription() string
- func (x *Schema) GetIsActive() bool
- func (x *Schema) GetMetadata() map[string]string
- func (x *Schema) GetName() string
- func (x *Schema) GetSchemaId() string
- func (x *Schema) GetUpdatedAt() int64
- func (x *Schema) GetVersion() int32
- func (*Schema) ProtoMessage()
- func (x *Schema) ProtoReflect() protoreflect.Message
- func (x *Schema) Reset()
- func (x *Schema) String() string
- type ValidationError
- func (*ValidationError) Descriptor() ([]byte, []int)deprecated
- func (x *ValidationError) GetDetails() map[string]string
- func (x *ValidationError) GetErrorCode() string
- func (x *ValidationError) GetField() string
- func (x *ValidationError) GetMessage() string
- func (*ValidationError) ProtoMessage()
- func (x *ValidationError) ProtoReflect() protoreflect.Message
- func (x *ValidationError) Reset()
- func (x *ValidationError) String() string
- type ValidationResult
- func (*ValidationResult) Descriptor() ([]byte, []int)deprecated
- func (x *ValidationResult) GetErrors() []*ValidationError
- func (x *ValidationResult) GetSchemaId() string
- func (x *ValidationResult) GetSchemaVersion() int32
- func (x *ValidationResult) GetValid() bool
- func (x *ValidationResult) GetValidatedAt() int64
- func (*ValidationResult) ProtoMessage()
- func (x *ValidationResult) ProtoReflect() protoreflect.Message
- func (x *ValidationResult) Reset()
- func (x *ValidationResult) String() string
Constants ¶
This section is empty.
Variables ¶
var ( ErrorCode_name = map[int32]string{ 0: "UNKNOWN_ERROR", 1: "REQUIRED_FIELD_MISSING", 2: "INVALID_TYPE", 3: "INVALID_FORMAT", 4: "PATTERN_MISMATCH", 5: "VALUE_OUT_OF_RANGE", 6: "ARRAY_LENGTH_INVALID", 7: "OBJECT_PROPERTIES_INVALID", 8: "ADDITIONAL_PROPERTIES_NOT_ALLOWED", 9: "ENUM_VALUE_INVALID", 10: "SCHEMA_NOT_FOUND", 11: "CONTENT_TYPE_INVALID", 12: "PAYLOAD_SIZE_EXCEEDED", 13: "SCHEMA_VALIDATION_FAILED", } ErrorCode_value = map[string]int32{ "UNKNOWN_ERROR": 0, "REQUIRED_FIELD_MISSING": 1, "INVALID_TYPE": 2, "INVALID_FORMAT": 3, "PATTERN_MISMATCH": 4, "VALUE_OUT_OF_RANGE": 5, "ARRAY_LENGTH_INVALID": 6, "OBJECT_PROPERTIES_INVALID": 7, "ADDITIONAL_PROPERTIES_NOT_ALLOWED": 8, "ENUM_VALUE_INVALID": 9, "SCHEMA_NOT_FOUND": 10, "CONTENT_TYPE_INVALID": 11, "PAYLOAD_SIZE_EXCEEDED": 12, "SCHEMA_VALIDATION_FAILED": 13, } )
Enum value maps for ErrorCode.
var File_proto_schema_v1_schema_proto protoreflect.FileDescriptor
Functions ¶
This section is empty.
Types ¶
type ErrorCode ¶
type ErrorCode int32
ErrorCode enum for standardized validation error classification.
Use these codes to: - Handle specific error types programmatically - Display user-friendly error messages - Track validation failure metrics by category
Mapping to JSON Schema validation errors:
REQUIRED_FIELD_MISSING = "required" keyword INVALID_TYPE = "type" keyword PATTERN_MISMATCH = "pattern" keyword VALUE_OUT_OF_RANGE = "minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum" ARRAY_LENGTH_INVALID = "minItems", "maxItems" ENUM_VALUE_INVALID = "enum" keyword
const ( // UNKNOWN_ERROR: Unclassified validation error. // Check message field for details. ErrorCode_UNKNOWN_ERROR ErrorCode = 0 // REQUIRED_FIELD_MISSING: A required field is absent. // Corresponds to JSON Schema "required" keyword. ErrorCode_REQUIRED_FIELD_MISSING ErrorCode = 1 // INVALID_TYPE: Field has wrong type. // Example: Expected integer, got string. // Corresponds to JSON Schema "type" keyword. ErrorCode_INVALID_TYPE ErrorCode = 2 // INVALID_FORMAT: Field value doesn't match expected format. // Example: Invalid email, UUID, date-time, URI. // Corresponds to JSON Schema "format" keyword. ErrorCode_INVALID_FORMAT ErrorCode = 3 // PATTERN_MISMATCH: String doesn't match regex pattern. // Example: Phone number doesn't match "^\d{3}-\d{3}-\d{4}$". // Corresponds to JSON Schema "pattern" keyword. ErrorCode_PATTERN_MISMATCH ErrorCode = 4 // VALUE_OUT_OF_RANGE: Numeric value outside allowed range. // Example: Age is -5 (minimum is 0). // Corresponds to JSON Schema "minimum", "maximum", etc. ErrorCode_VALUE_OUT_OF_RANGE ErrorCode = 5 // ARRAY_LENGTH_INVALID: Array has wrong number of elements. // Example: Order must have 1-10 items, got 0. // Corresponds to JSON Schema "minItems", "maxItems". ErrorCode_ARRAY_LENGTH_INVALID ErrorCode = 6 // OBJECT_PROPERTIES_INVALID: Object has wrong properties. // Example: Missing required nested field. // Corresponds to JSON Schema object validation. ErrorCode_OBJECT_PROPERTIES_INVALID ErrorCode = 7 // ADDITIONAL_PROPERTIES_NOT_ALLOWED: Object has unexpected fields. // Occurs when schema sets "additionalProperties": false. ErrorCode_ADDITIONAL_PROPERTIES_NOT_ALLOWED ErrorCode = 8 // ENUM_VALUE_INVALID: Value not in allowed enum set. // Example: status must be "pending" or "completed", got "unknown". // Corresponds to JSON Schema "enum" keyword. ErrorCode_ENUM_VALUE_INVALID ErrorCode = 9 // SCHEMA_NOT_FOUND: Referenced schema doesn't exist. // Occurs when queue references non-existent schema_id. ErrorCode_SCHEMA_NOT_FOUND ErrorCode = 10 // CONTENT_TYPE_INVALID: Payload content_type incompatible with schema. // Example: Schema expects JSON, payload is "application/protobuf". ErrorCode_CONTENT_TYPE_INVALID ErrorCode = 11 // PAYLOAD_SIZE_EXCEEDED: Payload exceeds size limit. // ChronoQueue has a default 1MB payload limit. ErrorCode_PAYLOAD_SIZE_EXCEEDED ErrorCode = 12 // SCHEMA_VALIDATION_FAILED: Schema content itself is invalid. // Occurs when registering schema with malformed content. ErrorCode_SCHEMA_VALIDATION_FAILED ErrorCode = 13 )
func (ErrorCode) Descriptor ¶
func (ErrorCode) Descriptor() protoreflect.EnumDescriptor
func (ErrorCode) EnumDescriptor
deprecated
func (ErrorCode) Number ¶
func (x ErrorCode) Number() protoreflect.EnumNumber
func (ErrorCode) Type ¶
func (ErrorCode) Type() protoreflect.EnumType
type Schema ¶
type Schema struct {
// schema_id: Unique identifier for this schema family.
// All versions of the same schema share this ID.
// Example: "order-schema", "user-event-schema"
SchemaId string `protobuf:"bytes,1,opt,name=schema_id,json=schemaId,proto3" json:"schema_id,omitempty"`
// version: Schema version number (positive integer).
// Increment when making changes to the schema.
// Semantic versioning recommended:
//
// v1 -> v2: backward compatible changes (add optional fields)
// v2 -> v3: breaking changes (remove/rename fields, change types)
Version int32 `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"`
// name: Human-readable schema name.
// Example: "Order Validation Schema v2", "User Registration Event"
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
// description: Detailed description of what this schema validates.
// Include changelog for new versions.
// Example: "v2: Added optional 'discountCode' field. Removed deprecated 'legacyField'."
Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"`
// content: The actual validation schema.
// Format depends on content_type.
// For "json-schema": JSON Schema Draft 7 (https://json-schema.org/)
// For "protobuf": Base64-encoded FileDescriptorSet
// Size limit: 1MB
Content string `protobuf:"bytes,5,opt,name=content,proto3" json:"content,omitempty"`
// content_type: Schema format identifier.
// Supported values:
//
// "json-schema" (default): JSON Schema Draft 7
// "protobuf": Protocol Buffers schema
// "avro": Apache Avro schema
//
// ChronoQueue validates content syntax when registering schema.
ContentType string `protobuf:"bytes,6,opt,name=content_type,json=contentType,proto3" json:"content_type,omitempty"`
// created_at: When this schema version was registered (Unix milliseconds).
// Automatically set by ChronoQueue.
CreatedAt int64 `protobuf:"varint,7,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
// updated_at: When this schema was last modified (Unix milliseconds).
// Schemas are immutable after creation; updates create new versions.
// This tracks metadata changes (name, description, is_active).
UpdatedAt int64 `protobuf:"varint,8,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
// is_active: Whether this schema version can be used for validation.
// Set to false to deprecate old versions.
// Queues configured with this schema_id will use the highest active version.
// Use case: Deactivate v1 after all clients migrate to v2.
IsActive bool `protobuf:"varint,9,opt,name=is_active,json=isActive,proto3" json:"is_active,omitempty"`
// metadata: Additional schema metadata.
// Use for:
//
// "owner": "team-checkout"
// "deprecation_date": "2025-01-01"
// "changelog_url": "https://..."
// "contact": "checkout-team@example.com"
Metadata map[string]string `` /* 144-byte string literal not displayed */
// contains filtered or unexported fields
}
Schema defines a message validation schema.
ChronoQueue validates message payloads against schemas before accepting them. This prevents invalid messages from entering your queues.
Schema evolution: 1. Create v1: Initial schema 2. Create v2: Add optional fields (backward compatible) 3. Update producers to v2 4. Update consumers to v2 5. Deprecate v1 when all clients upgraded
Example - Order schema:
schema := &schema.Schema{
SchemaId: "order-schema",
Version: 1,
Name: "Order Validation Schema",
Content: `{
"type": "object",
"required": ["orderId", "customerId", "items"],
"properties": {
"orderId": {"type": "string", "pattern": "^ORD-[0-9]+$"},
"customerId": {"type": "string"},
"items": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": ["productId", "quantity"],
"properties": {
"productId": {"type": "string"},
"quantity": {"type": "integer", "minimum": 1}
}
}
},
"totalAmount": {"type": "number", "minimum": 0}
}
}`,
ContentType: "json-schema",
IsActive: true,
}
Then reference in Queue:
queue := &queue.Queue{
Name: "order-processing",
Metadata: &queue.QueueMetadata{
SchemaId: "order-schema",
SchemaRequired: true, // Reject invalid messages
},
}
func (*Schema) Descriptor
deprecated
func (*Schema) GetContent ¶
func (*Schema) GetContentType ¶
func (*Schema) GetCreatedAt ¶
func (*Schema) GetDescription ¶
func (*Schema) GetIsActive ¶
func (*Schema) GetMetadata ¶
func (*Schema) GetSchemaId ¶
func (*Schema) GetUpdatedAt ¶
func (*Schema) GetVersion ¶
func (*Schema) ProtoMessage ¶
func (*Schema) ProtoMessage()
func (*Schema) ProtoReflect ¶
func (x *Schema) ProtoReflect() protoreflect.Message
type ValidationError ¶
type ValidationError struct {
// field: JSON path to the field that failed validation.
// Uses dot notation: "payload.data.orderId", "payload.data.items[0].productId"
// Root level: "payload.data"
Field string `protobuf:"bytes,1,opt,name=field,proto3" json:"field,omitempty"`
// error_code: Standardized error code from ErrorCode enum.
// Enables programmatic error handling across different schema types.
ErrorCode string `protobuf:"bytes,2,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"`
// message: Human-readable error explanation.
// Safe to show to end users or log for debugging.
// Example: "Field 'orderId' must match pattern '^ORD-[0-9]+$', got 'invalid'"
Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"`
// details: Additional context about the error.
// Contents depend on error_code:
//
// INVALID_TYPE: {"expected": "integer", "actual": "string"}
// PATTERN_MISMATCH: {"pattern": "^[A-Z]+$", "value": "abc"}
// VALUE_OUT_OF_RANGE: {"min": "0", "max": "100", "value": "150"}
Details map[string]string `` /* 141-byte string literal not displayed */
// contains filtered or unexported fields
}
ValidationError provides detailed information about a validation failure.
Each error describes: - Which field failed (field path) - Why it failed (error_code) - Human-readable explanation (message) - Additional context (details)
Example errors:
Field "payload.data.orderId" - REQUIRED_FIELD_MISSING:
{field: "payload.data.orderId", error_code: "REQUIRED_FIELD_MISSING",
message: "Required field 'orderId' is missing"}
Field "payload.data.quantity" - INVALID_TYPE:
{field: "payload.data.quantity", error_code: "INVALID_TYPE",
message: "Expected integer, got string",
details: {"expected": "integer", "actual": "string"}}
func (*ValidationError) Descriptor
deprecated
func (*ValidationError) Descriptor() ([]byte, []int)
Deprecated: Use ValidationError.ProtoReflect.Descriptor instead.
func (*ValidationError) GetDetails ¶
func (x *ValidationError) GetDetails() map[string]string
func (*ValidationError) GetErrorCode ¶
func (x *ValidationError) GetErrorCode() string
func (*ValidationError) GetField ¶
func (x *ValidationError) GetField() string
func (*ValidationError) GetMessage ¶
func (x *ValidationError) GetMessage() string
func (*ValidationError) ProtoMessage ¶
func (*ValidationError) ProtoMessage()
func (*ValidationError) ProtoReflect ¶
func (x *ValidationError) ProtoReflect() protoreflect.Message
func (*ValidationError) Reset ¶
func (x *ValidationError) Reset()
func (*ValidationError) String ¶
func (x *ValidationError) String() string
type ValidationResult ¶
type ValidationResult struct {
// valid: True if payload passed validation, false otherwise.
Valid bool `protobuf:"varint,1,opt,name=valid,proto3" json:"valid,omitempty"`
// errors: List of validation errors (empty if valid = true).
// Each error describes one validation rule violation.
Errors []*ValidationError `protobuf:"bytes,2,rep,name=errors,proto3" json:"errors,omitempty"`
// validated_at: When validation was performed (Unix milliseconds).
ValidatedAt int64 `protobuf:"varint,3,opt,name=validated_at,json=validatedAt,proto3" json:"validated_at,omitempty"`
// schema_id: Which schema was used for validation.
SchemaId string `protobuf:"bytes,4,opt,name=schema_id,json=schemaId,proto3" json:"schema_id,omitempty"`
// schema_version: Which schema version was used.
// Helps debug validation failures after schema upgrades.
SchemaVersion int32 `protobuf:"varint,5,opt,name=schema_version,json=schemaVersion,proto3" json:"schema_version,omitempty"`
// contains filtered or unexported fields
}
ValidationResult contains the outcome of payload validation.
Returned by: - PostMessage API (if validation fails, message is rejected) - ValidatePayload API (dry-run validation before posting)
Example - handling validation errors:
result, err := client.PostMessage(ctx, &queueservice.PostMessageRequest{...})
if err != nil {
if status.Code(err) == codes.InvalidArgument {
// Check err.Details() for ValidationResult
for _, detail := range status.Convert(err).Details() {
if vr, ok := detail.(*schema.ValidationResult); ok {
for _, verr := range vr.Errors {
log.Printf("Field '%s' failed: %s", verr.Field, verr.Message)
}
}
}
}
}
func (*ValidationResult) Descriptor
deprecated
func (*ValidationResult) Descriptor() ([]byte, []int)
Deprecated: Use ValidationResult.ProtoReflect.Descriptor instead.
func (*ValidationResult) GetErrors ¶
func (x *ValidationResult) GetErrors() []*ValidationError
func (*ValidationResult) GetSchemaId ¶
func (x *ValidationResult) GetSchemaId() string
func (*ValidationResult) GetSchemaVersion ¶
func (x *ValidationResult) GetSchemaVersion() int32
func (*ValidationResult) GetValid ¶
func (x *ValidationResult) GetValid() bool
func (*ValidationResult) GetValidatedAt ¶
func (x *ValidationResult) GetValidatedAt() int64
func (*ValidationResult) ProtoMessage ¶
func (*ValidationResult) ProtoMessage()
func (*ValidationResult) ProtoReflect ¶
func (x *ValidationResult) ProtoReflect() protoreflect.Message
func (*ValidationResult) Reset ¶
func (x *ValidationResult) Reset()
func (*ValidationResult) String ¶
func (x *ValidationResult) String() string