types

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Any    = TypeFromString("any")
	Bool   = TypeFromString("bool")
	Char   = TypeFromString("char")
	Data   = TypeFromString("data")
	Number = TypeFromString("number")
	String = TypeFromString("string")

	AnyArray    = NewArray(Any)
	BoolArray   = NewArray(Bool)
	NumberArray = NewArray(Number)
	StringArray = NewArray(String)

	AnyMap    = NewMap(Any)
	NumberMap = NewMap(Number)
	StringMap = NewMap(String)

	ErrorInterface = NewInterface("error.Error", map[string]*Type{
		"Error": String,
	})
)

Functions

This section is empty.

Types

type Kind

type Kind int
const (
	// An unresolved interface (object type) is named, but the properties will
	// be nil because they are not known. This is a distinction from a resolved
	// interface which allowed to have zero or more properties.
	//
	// KindUnresolvedInterface = 0 on purpose it acts as a fallthrough/unknown
	// type.
	KindUnresolvedInterface Kind = iota
	KindResolvedInterface

	// Basic types.
	KindAny
	KindBool
	KindChar
	KindData
	KindNumber
	KindString

	// Other.
	KindArray
	KindMap
	KindFunc
)

type Registry added in v0.24.0

type Registry map[string]*Type

A Registry holds a collection of unique types that can are referenced internally to allow for circular references but also be serializable.

func (Registry) Add added in v0.24.0

func (registry Registry) Add(ty *Type) (string, error)

Add will merge new types into the register. An error is returned only if an unresolved interface type is added and there's no way to resolve it right now.

func (Registry) EqualTypeSlices added in v0.24.0

func (registry Registry) EqualTypeSlices(a, b []*Type) bool

func (Registry) EqualTypes added in v0.24.0

func (registry Registry) EqualTypes(a, b *Type) bool

EqualTypes ignores only the Name.

func (Registry) Get added in v0.24.0

func (registry Registry) Get(key string) *Type

type Type

type Type struct {
	// Kind will not be set when Ref is supplied.
	Kind Kind `json:",omitempty"`

	// Name is used as the descriptive name for the object.
	Name string `json:",omitempty"`

	// Element is used when Kind is an Array or Map.
	Element *Type `json:",omitempty"`

	// Argument and Returns are used when Kind is a Func. Either may be nil.
	Arguments, Returns []*Type `json:",omitempty"`

	// Properties is used for KindInterface
	Properties map[string]*Type `json:",omitempty"`

	// Ref is used when types are flattened for a Registry. It will point to an
	// index of another type in the registry.
	Ref string `json:",omitempty"`
}

Type represents a data type.

func NewArray added in v0.24.0

func NewArray(element *Type) *Type

func NewFunc

func NewFunc(args, returns []*Type) *Type

func NewInterface

func NewInterface(name string, properties map[string]*Type) *Type

func NewMap added in v0.24.0

func NewMap(element *Type) *Type

func NewRef added in v0.24.0

func NewRef(ref string) *Type

func NewUnresolvedInterface

func NewUnresolvedInterface(name string) *Type

func TypeFromString

func TypeFromString(s string) *Type

TypeFromString decodes a syntactically-valid type from a string.

func (*Type) Copy added in v0.24.0

func (t *Type) Copy() *Type

func (*Type) Interface added in v0.23.12

func (t *Type) Interface() string

func (*Type) SortedPropertyNames added in v0.24.0

func (t *Type) SortedPropertyNames() []string

func (*Type) String

func (t *Type) String() string

func (*Type) ToArray

func (t *Type) ToArray() *Type

ToArray creates an array type using this element type.

func (*Type) ToMap

func (t *Type) ToMap() *Type

ToMap creates a map type using this element type.

Jump to

Keyboard shortcuts

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