schema

package
v6.3.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

gogen-avro's internal representation of Avro schemas, and templates for code generation

Index

Constants

View Source
const UTIL_FILE = "primitive.go"

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayField

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

func NewArrayField

func NewArrayField(itemType AvroType, definition map[string]interface{}) *ArrayField

func (*ArrayField) AddStruct

func (s *ArrayField) AddStruct(p *generator.Package, container bool) error

func (*ArrayField) ConstructorMethod

func (s *ArrayField) ConstructorMethod() string

func (*ArrayField) DefaultValue

func (s *ArrayField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*ArrayField) Definition

func (s *ArrayField) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*ArrayField) GoType

func (s *ArrayField) GoType() string

func (*ArrayField) IsReadableBy

func (s *ArrayField) IsReadableBy(f AvroType) bool

func (*ArrayField) ItemConstructable

func (s *ArrayField) ItemConstructable() string

func (*ArrayField) ItemType

func (s *ArrayField) ItemType() AvroType

func (*ArrayField) Name

func (s *ArrayField) Name() string

func (*ArrayField) ResolveReferences

func (s *ArrayField) ResolveReferences(n *Namespace) error

func (*ArrayField) SerializerMethod

func (s *ArrayField) SerializerMethod() string

func (*ArrayField) SimpleName

func (s *ArrayField) SimpleName() string

func (*ArrayField) WrapperType

func (s *ArrayField) WrapperType() string

type AvroType

type AvroType interface {
	Name() string
	SimpleName() string
	GoType() string

	// The name of the method which writes this field onto the wire
	SerializerMethod() string

	// Add the imports and struct for the definition of this type to the generator.Package
	AddStruct(*generator.Package, bool) error

	// Attempt to resolve references to named structs, enums or fixed fields
	ResolveReferences(*Namespace) error

	Definition(scope map[QualifiedName]interface{}) (interface{}, error)
	DefaultValue(lvalue string, rvalue interface{}) (string, error)

	WrapperType() string
	IsReadableBy(f AvroType) bool
}

type BoolField

type BoolField struct {
	PrimitiveField
}

func NewBoolField

func NewBoolField(definition interface{}) *BoolField

func (*BoolField) DefaultValue

func (s *BoolField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*BoolField) IsReadableBy

func (s *BoolField) IsReadableBy(f AvroType) bool

func (*BoolField) WrapperType

func (s *BoolField) WrapperType() string

type BytesField

type BytesField struct {
	PrimitiveField
}

func NewBytesField

func NewBytesField(definition interface{}) *BytesField

func (*BytesField) DefaultValue

func (s *BytesField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*BytesField) IsReadableBy

func (s *BytesField) IsReadableBy(f AvroType) bool

func (*BytesField) WrapperType

func (s *BytesField) WrapperType() string

type Constructable

type Constructable interface {
	ConstructorMethod() string
}

type Definition

type Definition interface {
	AvroName() QualifiedName
	Aliases() []QualifiedName

	// A user-friendly name that can be built into a Go string (for unions, mostly)
	Name() string
	SimpleName() string

	GoType() string

	SerializerMethod() string

	// Add the imports and struct for the definition of this type to the generator.Package
	AddStruct(*generator.Package, bool) error

	// Resolve references to user-defined types
	ResolveReferences(*Namespace) error

	// A JSON object defining this object, for writing the schema back out
	Definition(scope map[QualifiedName]interface{}) (interface{}, error)
	DefaultValue(lvalue string, rvalue interface{}) (string, error)

	IsReadableBy(f Definition) bool
	WrapperType() string
}

type DoubleField

type DoubleField struct {
	PrimitiveField
}

func NewDoubleField

func NewDoubleField(definition interface{}) *DoubleField

func (*DoubleField) DefaultValue

func (s *DoubleField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*DoubleField) IsReadableBy

func (s *DoubleField) IsReadableBy(f AvroType) bool

func (*DoubleField) WrapperType

func (s *DoubleField) WrapperType() string

type EnumDefinition

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

func NewEnumDefinition

func NewEnumDefinition(name QualifiedName, aliases []QualifiedName, symbols []string, doc string, definition map[string]interface{}) *EnumDefinition

func (*EnumDefinition) AddStruct

func (e *EnumDefinition) AddStruct(p *generator.Package, _ bool) error

func (*EnumDefinition) Aliases

func (e *EnumDefinition) Aliases() []QualifiedName

func (*EnumDefinition) AvroName

func (e *EnumDefinition) AvroName() QualifiedName

func (*EnumDefinition) DefaultValue

func (s *EnumDefinition) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*EnumDefinition) Definition

func (s *EnumDefinition) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*EnumDefinition) Doc

func (e *EnumDefinition) Doc() string

func (*EnumDefinition) FromStringMethod

func (e *EnumDefinition) FromStringMethod() string

func (*EnumDefinition) GoType

func (e *EnumDefinition) GoType() string

func (*EnumDefinition) IsReadableBy

func (s *EnumDefinition) IsReadableBy(d Definition) bool

func (*EnumDefinition) Name

func (e *EnumDefinition) Name() string

func (*EnumDefinition) ResolveReferences

func (s *EnumDefinition) ResolveReferences(n *Namespace) error

func (*EnumDefinition) SerializerMethod

func (e *EnumDefinition) SerializerMethod() string

func (*EnumDefinition) SimpleName

func (e *EnumDefinition) SimpleName() string

func (*EnumDefinition) SymbolName

func (e *EnumDefinition) SymbolName(symbol string) string

func (*EnumDefinition) Symbols

func (e *EnumDefinition) Symbols() []string

func (*EnumDefinition) WrapperType

func (s *EnumDefinition) WrapperType() string

type Field

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

func NewField

func NewField(avroName string, avroType AvroType, defValue interface{}, hasDef bool, aliases []string, doc string, definition map[string]interface{}, index int, fieldTags string) *Field

func (*Field) Default

func (f *Field) Default() interface{}

func (*Field) Definition

func (f *Field) Definition(scope map[QualifiedName]interface{}) (map[string]interface{}, error)

func (*Field) Doc

func (f *Field) Doc() string

func (*Field) GoName

func (f *Field) GoName() string

func (*Field) HasDefault

func (f *Field) HasDefault() bool

func (*Field) Index

func (f *Field) Index() int

func (*Field) IsSameField

func (f *Field) IsSameField(otherField *Field) bool

IsSameField checks whether two fields have the same name or any of their aliases are the same, in which case they're the same for purposes of schema evolution

func (*Field) Name

func (f *Field) Name() string

func (*Field) NameMatchesAliases

func (f *Field) NameMatchesAliases(name string) bool

func (*Field) SimpleName

func (f *Field) SimpleName() string

func (*Field) Tags

func (f *Field) Tags() string

Tags returns a field go struct tags if defined.

func (*Field) Type

func (f *Field) Type() AvroType

type FixedDefinition

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

func NewFixedDefinition

func NewFixedDefinition(name QualifiedName, aliases []QualifiedName, sizeBytes int, definition map[string]interface{}) *FixedDefinition

func (*FixedDefinition) AddStruct

func (s *FixedDefinition) AddStruct(p *generator.Package, _ bool) error

func (*FixedDefinition) Aliases

func (s *FixedDefinition) Aliases() []QualifiedName

func (*FixedDefinition) AvroName

func (s *FixedDefinition) AvroName() QualifiedName

func (*FixedDefinition) DefaultValue

func (s *FixedDefinition) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*FixedDefinition) Definition

func (s *FixedDefinition) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*FixedDefinition) GoType

func (s *FixedDefinition) GoType() string

func (*FixedDefinition) IsReadableBy

func (s *FixedDefinition) IsReadableBy(d Definition) bool

func (*FixedDefinition) Name

func (s *FixedDefinition) Name() string

func (*FixedDefinition) ResolveReferences

func (s *FixedDefinition) ResolveReferences(n *Namespace) error

func (*FixedDefinition) SerializerMethod

func (s *FixedDefinition) SerializerMethod() string

func (*FixedDefinition) SimpleName

func (s *FixedDefinition) SimpleName() string

func (*FixedDefinition) SizeBytes

func (s *FixedDefinition) SizeBytes() int

func (*FixedDefinition) WrapperType

func (s *FixedDefinition) WrapperType() string

type FloatField

type FloatField struct {
	PrimitiveField
}

func NewFloatField

func NewFloatField(definition interface{}) *FloatField

func (*FloatField) DefaultValue

func (s *FloatField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*FloatField) IsReadableBy

func (s *FloatField) IsReadableBy(f AvroType) bool

func (*FloatField) WrapperType

func (s *FloatField) WrapperType() string

type IntField

type IntField struct {
	PrimitiveField
}

func NewIntField

func NewIntField(definition interface{}) *IntField

func (*IntField) DefaultValue

func (s *IntField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*IntField) IsReadableBy

func (s *IntField) IsReadableBy(f AvroType) bool

func (*IntField) WrapperType

func (s *IntField) WrapperType() string

type LongField

type LongField struct {
	PrimitiveField
}

func NewLongField

func NewLongField(definition interface{}) *LongField

func (*LongField) DefaultValue

func (s *LongField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*LongField) IsReadableBy

func (s *LongField) IsReadableBy(f AvroType) bool

func (*LongField) WrapperType

func (s *LongField) WrapperType() string

type MapField

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

func NewMapField

func NewMapField(itemType AvroType, definition map[string]interface{}) *MapField

func (*MapField) AddStruct

func (s *MapField) AddStruct(p *generator.Package, containers bool) error

func (*MapField) ConstructorMethod

func (s *MapField) ConstructorMethod() string

func (*MapField) DefaultValue

func (s *MapField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*MapField) Definition

func (s *MapField) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*MapField) GoType

func (s *MapField) GoType() string

func (*MapField) IsReadableBy

func (s *MapField) IsReadableBy(f AvroType) bool

func (*MapField) ItemConstructable

func (s *MapField) ItemConstructable() string

func (*MapField) ItemType

func (s *MapField) ItemType() AvroType

func (*MapField) Name

func (s *MapField) Name() string

func (*MapField) ResolveReferences

func (s *MapField) ResolveReferences(n *Namespace) error

func (*MapField) SerializerMethod

func (s *MapField) SerializerMethod() string

func (*MapField) SimpleName

func (s *MapField) SimpleName() string

func (*MapField) WrapperType

func (s *MapField) WrapperType() string

type Namespace

type Namespace struct {
	Definitions map[QualifiedName]Definition
	Schemas     []Schema
	ShortUnions bool
}

Namespace is a mapping of QualifiedNames to their Definitions, used to resolve type lookups within a schema.

func NewNamespace

func NewNamespace(shortUnions bool) *Namespace

func (*Namespace) AddToPackage

func (namespace *Namespace) AddToPackage(p *generator.Package, headerComment string, containers bool) error

func (*Namespace) RegisterDefinition

func (n *Namespace) RegisterDefinition(d Definition) error

RegisterDefinition adds a new type definition to the namespace. Returns an error if the type is already defined.

func (*Namespace) TypeForSchema

func (n *Namespace) TypeForSchema(schemaJson []byte) (AvroType, error)

TypeForSchema accepts an Avro schema as a JSON string, decode it and return the AvroType defined at the top level:

  • a single record definition (JSON map)
  • a union of multiple types (JSON array)
  • an already-defined type (JSON string)

The Avro type defined at the top level and all the type definitions beneath it will also be added to this Namespace.

type NullField

type NullField struct {
	PrimitiveField
}

func NewNullField

func NewNullField(definition interface{}) *NullField

func (*NullField) DefaultValue

func (s *NullField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*NullField) IsReadableBy

func (s *NullField) IsReadableBy(f AvroType) bool

func (*NullField) WrapperType

func (s *NullField) WrapperType() string

type PrimitiveField

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

Common methods for all primitive types

func (*PrimitiveField) AddStruct

func (s *PrimitiveField) AddStruct(p *generator.Package, _ bool) error

func (*PrimitiveField) Definition

func (s *PrimitiveField) Definition(_ map[QualifiedName]interface{}) (interface{}, error)

func (*PrimitiveField) GoType

func (s *PrimitiveField) GoType() string

func (*PrimitiveField) Name

func (s *PrimitiveField) Name() string

func (*PrimitiveField) ResolveReferences

func (s *PrimitiveField) ResolveReferences(n *Namespace) error

func (*PrimitiveField) SerializerMethod

func (s *PrimitiveField) SerializerMethod() string

func (*PrimitiveField) SimpleName

func (s *PrimitiveField) SimpleName() string

type QualifiedName

type QualifiedName struct {
	Namespace string
	Name      string
}

QualifiedName represents an Avro qualified name, which includes an optional namespace and the type name.

func ParseAvroName

func ParseAvroName(enclosing, name string) QualifiedName

ParseAvroName parses a name according to the Avro spec:

  • If the name contains a dot ('.'), the last part is the name and the rest is the namespace
  • Otherwise, the enclosing namespace is used

func (QualifiedName) String

func (q QualifiedName) String() string

type RecordDefinition

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

func NewRecordDefinition

func NewRecordDefinition(name QualifiedName, aliases []QualifiedName, fields []*Field, doc string, metadata map[string]interface{}) *RecordDefinition

func (*RecordDefinition) AddStruct

func (r *RecordDefinition) AddStruct(p *generator.Package, containers bool) error

func (*RecordDefinition) Aliases

func (r *RecordDefinition) Aliases() []QualifiedName

func (*RecordDefinition) AvroName

func (r *RecordDefinition) AvroName() QualifiedName

func (*RecordDefinition) ConstructableForField

func (r *RecordDefinition) ConstructableForField(f *Field) string

func (*RecordDefinition) ConstructorMethod

func (r *RecordDefinition) ConstructorMethod() string

func (*RecordDefinition) DefaultForField

func (r *RecordDefinition) DefaultForField(f *Field) (string, error)

func (*RecordDefinition) DefaultValue

func (r *RecordDefinition) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*RecordDefinition) Definition

func (r *RecordDefinition) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*RecordDefinition) Doc

func (s *RecordDefinition) Doc() string

func (*RecordDefinition) FieldByName

func (r *RecordDefinition) FieldByName(field string) *Field

func (*RecordDefinition) Fields

func (r *RecordDefinition) Fields() []*Field

func (*RecordDefinition) GetReaderField

func (r *RecordDefinition) GetReaderField(writerField *Field) *Field

func (*RecordDefinition) GoType

func (r *RecordDefinition) GoType() string

func (*RecordDefinition) IsReadableBy

func (s *RecordDefinition) IsReadableBy(d Definition) bool

func (*RecordDefinition) Name

func (r *RecordDefinition) Name() string

func (*RecordDefinition) NewWriterMethod

func (r *RecordDefinition) NewWriterMethod() string

func (*RecordDefinition) RecordReaderTypeName

func (r *RecordDefinition) RecordReaderTypeName() string

func (*RecordDefinition) ResolveReferences

func (r *RecordDefinition) ResolveReferences(n *Namespace) error

func (*RecordDefinition) Schema

func (s *RecordDefinition) Schema() (string, error)

func (*RecordDefinition) SerializerMethod

func (r *RecordDefinition) SerializerMethod() string

func (*RecordDefinition) SimpleName

func (r *RecordDefinition) SimpleName() string

func (*RecordDefinition) WrapperType

func (s *RecordDefinition) WrapperType() string

type Reference

type Reference struct {
	TypeName QualifiedName
	Def      Definition
}

func NewReference

func NewReference(typeName QualifiedName) *Reference

func (*Reference) AddStruct

func (s *Reference) AddStruct(p *generator.Package, containers bool) error

func (*Reference) DefaultValue

func (s *Reference) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*Reference) Definition

func (s *Reference) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*Reference) GoType

func (s *Reference) GoType() string

func (*Reference) IsReadableBy

func (s *Reference) IsReadableBy(f AvroType) bool

func (*Reference) Name

func (s *Reference) Name() string

func (*Reference) ResolveReferences

func (s *Reference) ResolveReferences(n *Namespace) error

func (*Reference) SerializerMethod

func (s *Reference) SerializerMethod() string

func (*Reference) SimpleName

func (s *Reference) SimpleName() string

func (*Reference) WrapperType

func (s *Reference) WrapperType() string

type RequiredMapKeyError

type RequiredMapKeyError struct {
	Key string
}

func NewRequiredMapKeyError

func NewRequiredMapKeyError(key string) *RequiredMapKeyError

func (*RequiredMapKeyError) Error

func (r *RequiredMapKeyError) Error() string

type Schema

type Schema struct {
	Root       AvroType
	JSONSchema []byte
}

type SchemaError

type SchemaError struct {
	FieldName   string
	NestedError error
}

func NewSchemaError

func NewSchemaError(fieldName string, err error) *SchemaError

func (*SchemaError) Error

func (s *SchemaError) Error() string

type StringField

type StringField struct {
	PrimitiveField
}

func NewStringField

func NewStringField(definition interface{}) *StringField

func (*StringField) DefaultValue

func (s *StringField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*StringField) IsReadableBy

func (s *StringField) IsReadableBy(f AvroType) bool

func (*StringField) WrapperType

func (s *StringField) WrapperType() string

type UnionField

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

func NewUnionField

func NewUnionField(name string, itemType []AvroType, definition []interface{}) *UnionField

func (*UnionField) AddStruct

func (s *UnionField) AddStruct(p *generator.Package, containers bool) error

func (*UnionField) AvroTypes

func (s *UnionField) AvroTypes() []AvroType

func (*UnionField) ConstructorMethod

func (s *UnionField) ConstructorMethod() string

func (*UnionField) DefaultValue

func (s *UnionField) DefaultValue(lvalue string, rvalue interface{}) (string, error)

func (*UnionField) Definition

func (s *UnionField) Definition(scope map[QualifiedName]interface{}) (interface{}, error)

func (*UnionField) Equals

func (s *UnionField) Equals(reader *UnionField) bool

func (*UnionField) GoType

func (s *UnionField) GoType() string

func (*UnionField) IsReadableBy

func (s *UnionField) IsReadableBy(f AvroType) bool

func (*UnionField) ItemConstructor

func (s *UnionField) ItemConstructor(f AvroType) string

func (*UnionField) ItemName

func (s *UnionField) ItemName(item AvroType) string

func (*UnionField) ItemTypes

func (s *UnionField) ItemTypes() []AvroType

func (*UnionField) Name

func (s *UnionField) Name() string

func (*UnionField) ResolveReferences

func (s *UnionField) ResolveReferences(n *Namespace) error

func (*UnionField) SerializerMethod

func (s *UnionField) SerializerMethod() string

func (*UnionField) SimpleName

func (s *UnionField) SimpleName() string

func (*UnionField) UnionEnumType

func (s *UnionField) UnionEnumType() string

func (*UnionField) WrapperType

func (s *UnionField) WrapperType() string

type WrongMapValueTypeError

type WrongMapValueTypeError struct {
	Key          string
	ExpectedType string
	ActualValue  interface{}
}

func NewWrongMapValueTypeError

func NewWrongMapValueTypeError(key, expectedType string, actualValue interface{}) *WrongMapValueTypeError

func (*WrongMapValueTypeError) Error

func (w *WrongMapValueTypeError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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