schemas

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultMetadataOptions = []func(field *AvroField){
	WithUUID,
	WithTimestamp,
	WithSource,
	WithSubEnvironment,
	WithOwner,
	WithOperation,
}

DefaultMetadataOptions contains the options required to build the default metadata

Functions

func ParseYAML

func ParseYAML(data []byte) (string, error)

ParseYAML parses a schema in YAML format and return it in Avro JSON format

func ResolveNamespaceAndName

func ResolveNamespaceAndName(subject, contents string) (string, string, error)

func ResolveSubject

func ResolveSubject(subject, contents string) (string, error)

func WithOperation

func WithOperation(field *AvroField)

func WithOwner

func WithOwner(field *AvroField)

func WithPrimaryKeys

func WithPrimaryKeys(primaryKeys []string) func(field *AvroField)

func WithSource

func WithSource(field *AvroField)

func WithSubEnvironment

func WithSubEnvironment(field *AvroField)

func WithTimestamp

func WithTimestamp(field *AvroField)

func WithUUID

func WithUUID(field *AvroField)

Types

type AvroField

type AvroField struct {
	Name    string          `json:"name"`
	Doc     string          `json:"doc,omitempty"`
	Type    AvroTypeWrapper `json:"type,omitempty"`
	Default interface{}     `json:"default,omitempty"`
}

AvroField is a field of an Avro Schema

func NewMetadata

func NewMetadata(options ...func(field *AvroField)) AvroField

NewMetadata creates a new Metadata field with only the basic information filled

type AvroSchema

type AvroSchema struct {
	Type      string      `json:"type"`
	Name      string      `json:"name"`
	Namespace string      `json:"namespace"`
	Doc       string      `json:"doc"`
	Fields    []AvroField `json:"fields,omitempty"`
}

AvroSchema is the header for an Avro Schema

type AvroTypeObject

type AvroTypeObject struct {
	Type        string      `json:"type,omitempty"`
	Name        string      `json:"name,omitempty"`
	Namespace   string      `json:"namespace,omitempty"`
	Doc         string      `json:"doc,omitempty"`
	LogicalType string      `json:"logicalType,omitempty"`
	Symbols     []string    `json:"symbols,omitempty"`
	Fields      []AvroField `json:"fields,omitempty"`
	Items       string      `json:"items,omitempty"`
}

AvroTypeObject is the representation of a "type" field that is an object

type AvroTypeWrapper

type AvroTypeWrapper struct {
	Type     string             `json:"-"`
	TypeList []*AvroTypeWrapper `json:"-"`
	TypeObj  *AvroTypeObject    `json:"-"`
}

AvroTypeWrapper is a wrapper around the different Avro "type" field formats

func (AvroTypeWrapper) MarshalJSON

func (j AvroTypeWrapper) MarshalJSON() ([]byte, error)

MarshalJSON is a custom marshaling routine to process each kind of Avro "type" field

func (*AvroTypeWrapper) UnmarshalJSON

func (j *AvroTypeWrapper) UnmarshalJSON(data []byte) error

UnmarshalJSON tries to marshal to all possible "type"s and return an error if none matches

type BasicAuthClient

type BasicAuthClient struct {
	Username string
	Password string
	// contains filtered or unexported fields
}

func (BasicAuthClient) GetClient

func (c BasicAuthClient) GetClient() *http.Client

func (BasicAuthClient) RoundTrip

func (c BasicAuthClient) RoundTrip(r *http.Request) (*http.Response, error)

type JSON

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

JSON struct

func NewJSON

func NewJSON(writer io.Writer) *JSON

NewJSON create new JSON instance

func (*JSON) Generate

func (j *JSON) Generate(schemaPath string) error

Generate generate JSON

type LandoopRegistryClient

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

LandoopRegistryClient is the client for the Avro registry

func NewBasicAuthLandoopRegistryClient

func NewBasicAuthLandoopRegistryClient(registryURL string, username string, password string) (LandoopRegistryClient, error)

NewBasicAuthLandoopRegistryClient returns a new registry client with basic authentication.

func (LandoopRegistryClient) GetAllSchemaVersions

func (c LandoopRegistryClient) GetAllSchemaVersions(subject string) ([]AvroSchema, error)

GetAllSchemaVersions returns all schema versions of a given subject

func (LandoopRegistryClient) GetSchemaBySubject

func (c LandoopRegistryClient) GetSchemaBySubject(subject string, version int) (*AvroSchema, error)

GetSchemaBySubject returns an AvroSchema for given subject and version

func (LandoopRegistryClient) IsLatestSchemaCompatible

func (c LandoopRegistryClient) IsLatestSchemaCompatible(subject string, avroSchema string) (bool, error)

IsLatestSchemaCompatible tests compatibility with the latest version of a subject's schema.

func (LandoopRegistryClient) IsSchemaRegistered

func (c LandoopRegistryClient) IsSchemaRegistered(subject string, avroSchema string) (bool, error)

IsSchemaRegistered checks if this exact schema has already been registered

func (LandoopRegistryClient) IsSubjectNotFoundError

func (c LandoopRegistryClient) IsSubjectNotFoundError(err error) bool

IsSubjectNotFoundError checks the returned error to see if it is kind of a subject not found error code.

func (LandoopRegistryClient) RegisterNewSchema

func (c LandoopRegistryClient) RegisterNewSchema(subject string, avroSchema string) (int, error)

RegisterNewSchema registers a schema. Returns a schema id (not to be confused with the schema version)

func (LandoopRegistryClient) Versions

func (c LandoopRegistryClient) Versions(subject string) ([]int, error)

Versions returns all schema version numbers registered for this subject.

type NotifierClient

type NotifierClient interface {
	NotifySchemaChanged(namespace, name string, source string) error
}

type PubsubNotifierClient

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

func NewPubsubNotifierClient

func NewPubsubNotifierClient(projectID, topicName string) (PubsubNotifierClient, error)

func (PubsubNotifierClient) NotifySchemaChanged

func (n PubsubNotifierClient) NotifySchemaChanged(namespace, name, source string) error

type RegistryClient

type RegistryClient interface {
	RegisterNewSchema(subject, schema string) (int, error)
	IsSchemaRegistered(subject, schema string) (bool, error)
	IsLatestSchemaCompatible(subject, schema string) (bool, error)
	IsSubjectNotFoundError(err error) bool
	GetAllSchemaVersions(subject string) ([]AvroSchema, error)
	GetSchemaBySubject(subject string, version int) (*AvroSchema, error)
	Versions(subject string) ([]int, error)
}

RegistryClient provides an interface to the Avro registry

type SchemaHeader

type SchemaHeader struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
	Source    string `json:"source"`
}

type Validator

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

func NewValidator

func NewValidator(client RegistryClient) *Validator

func (*Validator) Validate

func (p *Validator) Validate(subject, schemaPath string, useYAML bool) (bool, error)

type YAMLField

type YAMLField struct {
	Name     string      `yaml:"name"`
	Doc      string      `yaml:"doc"`
	Type     interface{} `yaml:"type"`
	Required bool        `yaml:"required"`
}

YAMLField defines the field structure for unmarshal

type YAMLPayload

type YAMLPayload struct {
	Name string `yaml:"name"`
	Doc  string `yaml:"doc"`
}

YAMLPayload defines the payload structure for unmarshal

type YAMLSchema

type YAMLSchema struct {
	Name        string      `yaml:"name"`
	Namespace   string      `yaml:"namespace"`
	Doc         string      `yaml:"doc"`
	PrimaryKeys []string    `yaml:"primary_keys"`
	Payload     YAMLPayload `yaml:"payload"`
	Fields      []YAMLField `yaml:"fields"`
}

YAMLSchema defines the document structure for unmarshal

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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