schema

package
v1.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AvroValidator

type AvroValidator struct {
	// contains filtered or unexported fields
}

func NewAvroValidator

func NewAvroValidator(schemaStr string) (*AvroValidator, error)

func (*AvroValidator) Type

func (v *AvroValidator) Type() SchemaType

func (*AvroValidator) Validate

func (v *AvroValidator) Validate(ctx context.Context, data map[string]any) error

type JSONSchemaValidator

type JSONSchemaValidator struct {
	// contains filtered or unexported fields
}

func NewJSONSchemaValidator

func NewJSONSchemaValidator(schemaStr string) (*JSONSchemaValidator, error)

func (*JSONSchemaValidator) Type

func (v *JSONSchemaValidator) Type() SchemaType

func (*JSONSchemaValidator) Validate

func (v *JSONSchemaValidator) Validate(ctx context.Context, data map[string]any) error

type ProtobufValidator

type ProtobufValidator struct {
	// contains filtered or unexported fields
}

func NewProtobufValidator

func NewProtobufValidator(schemaStr string) (*ProtobufValidator, error)

func (*ProtobufValidator) Type

func (v *ProtobufValidator) Type() SchemaType

func (*ProtobufValidator) Validate

func (v *ProtobufValidator) Validate(ctx context.Context, data map[string]any) error

type Registry

type Registry interface {
	Register(ctx context.Context, name string, schemaType SchemaType, content string) (int, error)
	GetValidator(ctx context.Context, name string, version int) (Validator, error)
	GetLatestValidator(ctx context.Context, name string) (Validator, int, error)
	CheckCompatibility(ctx context.Context, name string, schemaType SchemaType, content string) error
}

Registry defines the interface for the global schema registry.

type SchemaConfig

type SchemaConfig struct {
	Type   SchemaType `json:"type"`
	Schema string     `json:"schema"` // The raw schema definition or URL
}

SchemaConfig contains the configuration for schema validation.

type SchemaType

type SchemaType string

SchemaType defines the supported schema formats.

const (
	Avro       SchemaType = "avro"
	JSONSchema SchemaType = "json"
	Protobuf   SchemaType = "protobuf"
)

type StorageRegistry

type StorageRegistry struct {
	// contains filtered or unexported fields
}

StorageRegistry implements Registry using the storage backend.

func NewStorageRegistry

func NewStorageRegistry(s storage.Storage) *StorageRegistry

NewStorageRegistry creates a new StorageRegistry.

func (*StorageRegistry) CheckCompatibility

func (r *StorageRegistry) CheckCompatibility(ctx context.Context, name string, schemaType SchemaType, content string) error

CheckCompatibility verifies if the new schema is compatible with previous versions. For now, it implements a basic check.

func (*StorageRegistry) GetLatestValidator

func (r *StorageRegistry) GetLatestValidator(ctx context.Context, name string) (Validator, int, error)

GetLatestValidator retrieves a validator for the latest schema version.

func (*StorageRegistry) GetValidator

func (r *StorageRegistry) GetValidator(ctx context.Context, name string, version int) (Validator, error)

GetValidator retrieves a validator for a specific schema version.

func (*StorageRegistry) Register

func (r *StorageRegistry) Register(ctx context.Context, name string, schemaType SchemaType, content string) (int, error)

Register adds a new schema version to the registry.

func (*StorageRegistry) SetStorage

func (r *StorageRegistry) SetStorage(s storage.Storage)

SetStorage updates the storage backend.

type Validator

type Validator interface {
	Validate(ctx context.Context, data map[string]any) error
	Type() SchemaType
}

Validator defines the interface for schema validation.

func NewValidator

func NewValidator(config SchemaConfig) (Validator, error)

NewValidator creates a new validator based on the provided configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL