Documentation ¶
Overview ¶
Package union contains shared code for union types.
In Go, one could use any to store values of various types. Union is different in a few important ways:
- Only a restricted set of types is admitted, whereas any can hold any type.
- Union types serialize in a way that makes it possible to distinguish among the possible types. Currently this is supported for types that serialize as strings; a possible development is to support types that serialize as other kinds of JSON nodes.
- Union types are indexable by Limestone (implement indices.IndexKey).
Go isn't flexible enough to make creation of new union types fully automatic, so this package only contains a common foundation for building your own union type. See iam/entities/irealm for an example of how to define a union type based on this package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Union ¶
type Union struct {
// contains filtered or unexported fields
}
A Union is a definition of a union type
func New ¶
New creates a new Union based on the given variants. The keys of the given map should be tags, and the values should be examples of variant type values.
func (Union) IndexKey ¶
IndexKey is a helper for implementing IndexKey expected by Limestone indices for union types
func (Union) MarshalText ¶
MarshalText is a helper for implementing encoding.TextMarshaler for union types
func (Union) StringValue ¶
StringValue returns a string representation of the value without the type tag (useful for API representation)
func (Union) UnmarshalText ¶
UnmarshalText is a helper for implementing encoding.TextUnmarshaler for union types