schema

package
v0.2.0-nightly.20220209 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcceptanceTest

func AcceptanceTest(t *testing.T, schema Schema)

AcceptanceTest is the acceptance test that all implementations of Schema should pass. It should manually be called from a test case in each implementation:

func TestSchema(t *testing.T) {
    s = NewSchema()
    schema.AcceptanceTest(t, s)
}

func DescriptorToString

func DescriptorToString(d Descriptor) string

DescriptorToString converts Descriptor into a human readable string.

func FieldToString

func FieldToString(f Field) string

FieldToString converts Field into a human readable string.

func ToString

func ToString(s Schema) string

ToString converts Schema into a human readable string.

Types

type ArrayDescriptor

type ArrayDescriptor interface {
	Descriptor

	// ValueDescriptor returns the descriptor for a value stored in the array.
	ValueDescriptor() Descriptor
	// contains filtered or unexported methods
}

ArrayDescriptor defines an array of values.

type Descriptor

type Descriptor interface {
	// Parameters returns additional settings specific for the schema type.
	Parameters() map[string]interface{}
}

Descriptor represents a Descriptor for a single type. Any Descriptor has to implement at least one of the following interfaces:

  • StructDescriptor or MutableStructDescriptor
  • MapDescriptor or MutableMapDescriptor
  • ArrayDescriptor or MutableArrayDescriptor
  • PrimitiveDescriptor or MutablePrimitiveDescriptor
  • EnumDescriptor or MutableEnumDescriptor
  • EnumValueDescriptor or MutableEnumValueDescriptor

type EnumDescriptor

type EnumDescriptor interface {
	Descriptor

	// Name returns the local name of the enum.
	Name() string
	// ValueDescriptors returns a slice of descriptors that define all possible
	// enum values.
	ValueDescriptors() []EnumValueDescriptor
	// contains filtered or unexported methods
}

EnumDescriptor defines an enumeration type with a finite set of possible values.

type EnumValueDescriptor

type EnumValueDescriptor interface {
	Descriptor

	// Name returns the local name of the enum value.
	Name() string
	// Value returns the value of the enum value.
	Value() string
	// contains filtered or unexported methods
}

EnumValueDescriptor defines a single enumeration value inside of an EnumDescriptor. It has a name and a value.

type Field

type Field interface {

	// Name returns the name of the field in its parent struct. The name of a
	// field has to be unique among all field names in a struct.
	Name() string
	// Index returns the numeric identifier of the field. The index of a field
	// has to be unique among all field indexes in a struct. NB: field indexes
	// are not necessarily consecutive (e.g. in protobuf schemas an index
	// represents the field number).
	Index() int
	// Descriptor returns the descriptor for the underlying field value.
	Descriptor() Descriptor
	// contains filtered or unexported methods
}

Field defines a single field inside of a StructDescriptor. It has a name, an index and a descriptor for the underlying value.

type MapDescriptor

type MapDescriptor interface {
	Descriptor

	// KeyDescriptor returns the descriptor for a map key.
	KeyDescriptor() Descriptor
	// KeyDescriptor returns the descriptor for a map value.
	ValueDescriptor() Descriptor
	// contains filtered or unexported methods
}

MapDescriptor defines a map with a single key and a value.

type MutableArrayDescriptor

type MutableArrayDescriptor interface {
	ArrayDescriptor
	SetValueDescriptor(MutableDescriptor)
}

MutableArrayDescriptor is a mutable instance of a ArrayDescriptor.

type MutableDescriptor

type MutableDescriptor interface {
	Descriptor
	// SetParameters sets additional settings specific for the schema type.
	SetParameters(map[string]interface{})
}

MutableDescriptor is a mutable instance of a Descriptor. Any MutableDescriptor has to implement at least one of the following interfaces:

  • MutableStructDescriptor
  • MutableMapDescriptor
  • MutableArrayDescriptor
  • MutablePrimitiveDescriptor
  • MutableEnumDescriptor
  • MutableEnumValueDescriptor

type MutableEnumDescriptor

type MutableEnumDescriptor interface {
	EnumDescriptor
	SetName(string)
	SetValueDescriptors([]MutableEnumValueDescriptor)
}

MutableEnumDescriptor is a mutable instance of a EnumDescriptor.

type MutableEnumValueDescriptor

type MutableEnumValueDescriptor interface {
	EnumValueDescriptor
	SetName(string)
	SetValue(string)
}

MutableEnumValueDescriptor is a mutable instance of a EnumValueDescriptor.

type MutableField

type MutableField interface {
	Field
	SetName(string)
	SetIndex(int)
	SetDescriptor(MutableDescriptor)
}

MutableField is a mutable instance of a Field.

type MutableMapDescriptor

type MutableMapDescriptor interface {
	MapDescriptor
	SetKeyDescriptor(MutableDescriptor)
	SetValueDescriptor(MutableDescriptor)
}

MutableMapDescriptor is a mutable instance of a MapDescriptor.

type MutablePrimitiveDescriptor

type MutablePrimitiveDescriptor interface {
	PrimitiveDescriptor
	SetType(PrimitiveDescriptorType)
}

MutablePrimitiveDescriptor is a mutable instance of a PrimitiveDescriptor.

type MutableSchema

type MutableSchema interface {
	// Type returns the schema type (e.g. protobuf).
	Type() string
	// Version represents the schema version. A higher version represents a
	// newer schema.
	Version() int
	// Descriptors returns descriptors defined at the root of this schema.
	Descriptors() []Descriptor

	// SetVersion sets the version.
	SetVersion(int)
	// SetDescriptors sets the descriptors defined at the root of this schema.
	// Any descriptors, that were defined before, are overwritten.
	SetDescriptors([]MutableDescriptor)

	// Build validates the schema, compiles it and returns an immutable Schema.
	// If the schema can't be validated or compiled it returns an error.
	Build() (Schema, error)
}

MutableSchema provides functionality for changing the underlying descriptors or the version of a schema and essentially building a new schema.

type MutableStructDescriptor

type MutableStructDescriptor interface {
	StructDescriptor
	SetName(string)
	SetFields([]MutableField)
}

MutableStructDescriptor is a mutable instance of a StructDescriptor.

type PrimitiveDescriptor

type PrimitiveDescriptor interface {
	Descriptor

	// Type returns the PrimitiveDescriptorType of the primitive value.
	Type() PrimitiveDescriptorType
	// contains filtered or unexported methods
}

PrimitiveDescriptor defines a value of a primitive type. Primitive types are constants of the type PrimitiveDescriptorType.

type PrimitiveDescriptorType

type PrimitiveDescriptorType int

PrimitiveDescriptorType represents the type of a PrimitiveDescriptor.

const (
	Unknown PrimitiveDescriptorType = iota

	Int32
	Int64

	UInt32
	UInt64

	Float32
	Float64

	Boolean
	String
	Bytes
)

func (PrimitiveDescriptorType) String

func (st PrimitiveDescriptorType) String() string

String formats PrimitiveDescriptorType to a human readable string.

type Schema

type Schema interface {
	// Type returns the schema type (e.g. protobuf).
	Type() string
	// Version represents the schema version. A higher version represents a
	// newer schema.
	Version() int
	// Descriptors returns descriptors defined at the root of this schema.
	Descriptors() []Descriptor
	// ToMutable returns a MutableSchema, that contains the same properties and
	// descriptors as this Schema, except that all of them are mutable.
	ToMutable() MutableSchema
}

Schema represents an immutable schema.

type StructDescriptor

type StructDescriptor interface {
	Descriptor

	// Name returns the local name of the struct.
	Name() string
	// Fields returns a slice of fields defined in this struct.
	Fields() []Field
	// contains filtered or unexported methods
}

StructDescriptor defines a struct type. A struct is a type with a name and 0 or more fields.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
data
This folder contains protobuf definitions used in tests.
This folder contains protobuf definitions used in tests.

Jump to

Keyboard shortcuts

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