runtime

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 15 Imported by: 13

README

Serialization and deserialization of formally typed objects

This package provides support for the de-/serialization of objects into/from a JSON or YAML representation.

Objects conforming to this model are called typed objects. They have a formal type, which determines the deserialization method. To be able to infer the type from the serialization format, it always contains a formal field type. So, the minimal external format of such an object would be (in JSON):

{ "type": "my-special-object-type" }

A dedicated realm of using typed objects is typically given by a common interface, the realm interface, which all implementations of objects in this realm must implement. For example, Access Specifications of the OCM all implement the AccessSpec interface. The various implementations of an access specification use dedicated objects to represent the property set for a dedicated kind of specification (for example localBlob or ociArtifact), which are able to provide an access method implementation for the given property set. All those specification types together build the access specification realm, with different specification types implemented as typed objects.

Core model types

Simple typed objects

Simple typed objects just feature an unstructured type name. Every type directly represents another flavor of the realm interface.

Go Types

interface TypedObject is the common interface for all kinds of typed objects. It provides access to the name of the type of the object.

interface TypedObjectType[T TypeObject] is the common interface all type objects have to implement. It provides information about the type name and a decode (and encode)method to deserialize/serialize an external JSON/YAML representation of the object. Its task is to handle the deserialization of instances/objects based of the type name taken from the deserialization format.

This interface is parameterized with the Go interface type representing the realm interface. As a result the Decode method provides a correctly typed typed-object according to the realm interface, which reflects the fact, that all objects in a realm have to implement this interface.

type ObjectTypedObject is the minimal implementation of a general typed object implementing the TypedObject interface. The minimal implementation of a typed object for a dedicated realm might require more according to the requirements of the realm interface.

*type ObjectType is an object providing the type name information of a typed object.

Support Functions

With the method NewTypedObjectTypeByDecoder[T TypedObject] a new type object can be created for the realm interface T by using a decoder able to map a byte representation to a typed object implementing the realm interface.

There might be other special implementations of the type interface.

With the method NewTypedObject a new minimal typed object can be created just featuring the type name.

A Go struct implementing a typed object typically looks like:

type MyTypedObject struct {
    ObjectTypeObject `json:",inline"
        ... other object properties
}
Versioned Types

Sometimes it is useful to support several versions for an external representation, which should all be handled by single internal version (Go type) in the rest of the coding. This can be supported by a flavor of a typed object, the versioned typed object.

A versioned type is described by a type name, which differentiates between a common kind and a format version. Here, there is an internal program facing representation given by a Go struct, which can be serialized into different format versions described by a version string (for example v1). Version name and kind are separated by a slash (/). A type name without a version implies the version v1.

Go Types

interface VersionedTypedObject is the common interface for all kinds of typed objects, which provides versioned type. If provides access to the type (like for plain TypedObjects, and its interpretation as a pair of kind and version).

interface VersionedTypedObjectType is the common interface all type objects for VersionedTypedObjects have to implement.

type ObjectVersionedTypedObject is the minimal implementation of a typed object implementing the VersionedTypedObject interface.

*type VersionedObjectType is an object providing the type information of a versioned typed object.

Support Functions

With the method NewVersionedTypedObjectTypeByDecoder[T TypedObject] a new type object can be created for the realm interface T by using a decoder able to map a byte representation to a typed object implementing the realm interface.

There might be other special implementation of the type interface.

There are several methods to define type objects for versioned typed objects.

  • Single external representation based on the internal representation.

    With the method NewVersionedTypedObjectType[T VersionedTypedObject, I VersionedTypedObject] a new type object is created for a new kind of objects in the realm given by the realm interface T. I is the struct pointer type if the internal Go representation also used to describe the single supported external format.

    With the method NewVersionedTypedObject a new minimal versioned typed object can be created just featuring the type information.

    A Go struct implementing a versioned typed object with just a single representation typically looks like:

    type MyVersionedTypedObject struct {
        ObjectVersionedTypeObject `json:",inline"
            ... other object properties
    }
    
  • Internal representation of a versioned typed object with multiple external representations. Here, the internal as well as the external representations are described by dedicated Go struct types. The internal version is never serialized directly but converted first to a Go object describing the external representation described by the version content of the type field.


    Such a conversion can be done by the MarshalJSON method of the internal version. The internal versions MUST be able to serialize themselves, because they might be embedded as field content in a larger serializable object.


    A better way than implementing it completely on ts own is to use dedicated type objects prepared for this. With the method NewVersionedTypedObjectTypeByConverter[T VersionedTypedObject, I VersionedTypedObject, V TypedObject] such a type object can be created for the realm interface T, the internal version I and the external representation V (both, I and V must be struct pointer types, where I must implement the realm interface T (cannot be expressed by Go generics)) and V just the typed object interface. A correctly typed converter object must be provided, which converts between I and V)

    ` For such types a dedicated base object representing the type part can be used to define the Go type for the internal version. InternalVersionedTypedObject[T VersionedTypedObject] keeps information about the type (kind and version) and the available serialization versions (used for the conversion to external versions as part of the serialization process). It can be created with NewInternalVersionedTypedObject[T VersionedTypedObject]. Here, a decoder object must be given, which can be a version scheme object provided by NewTypeVersionScheme[T VersionedTypedObject, R VersionedTypedObjectType[T]](kind string, reg VersionedTypeRegistry[T, R]). It can be used to register the various available external representation flavors by using the dedicated type objects. An example can be found in version_test.go.

      type MyVersionedTypedInternalObject struct {
          InternalVersionedTypedObject[MyInternalType] `json:",inline"
              ... other object properties
      }
    

    To complete the self-marshalling feature, the MarshalJSON method has to be implemented just by forwarding the requests to a runtime package function:

      func (a MyVersionedTypedInternalObject) MarshalJSON() ([]byte, error) {
        return runtime.MarshalVersionedTypedObject(&a)
      }
    

    If the base object from above is not used the version scheme can be passed as additional argument.

Internally, the different versions are represented with objects implementing the FormatVersion[T VersionedTypedObject] interface, where T is the internal representation. It provides the decoding/encoding for a dedicated format version. It can explicitly be created with the method NewSimpleVersion[T VersionedTypedObject, I VersionedTypedObject]() FormatVersion[T] for the single version flavor or NewConvertedVersion[T VersionedTypedObject, I VersionedTypedObject, V TypedObject](proto V, converter Converter[I, V]) for multiple flavored representations. Those format versions can be used to compose a type object with NewVersionedTypedObjectTypeByVersion

The runtime package handles both case the same way based such format version objects using an identity converter for the first case.

Schemes

interface Scheme[T TypedObject, R TypedObjectType[T] is a factory for typed objects of a dedicated realm, which hosts deserialization methods (interface TypedObjectDecoder) for dedicated types of typed objects. Basically it implements this task by hosting a set of appropriate decoders or type objects. It then delegates the task to the handler responsible for the typename in question. Hereby, T is the realm interface and R a dedicated Go interface for a type object. This interface may require more methods than a plain TypedObjectType by providing an own realm specific interface including the TypedObjectType[T TypedObject] interface.

Such a scheme may host types as well as plain decoders.

A type object implements such a decoder interface. For simple type objects, the serialization is typically just a JSON/YAML serialization of the underlying Go object representing the property set of this type. This is the default used by the scheme object, if the decoder does not implement the encoder interface.

The interface type TypeScheme[T TypedObject, R TypedObjectType[T]] can be used for schemes only using type objects and no plain decoders. It can be achieved for a dedicated realm by the function NewTypeScheme[T TypedObject, R TypedObjectType[T]](base ...TypeScheme[T, R]). Hereby, T is the realm interface and R a dedicated Go interface for a type object. It may require more methods than a plain TypedObjectType.

The same interface and constructor can be used for schemes for versioned typed objects, also. The type parameter in such cases must always be an extension of the Versioned... interface types.

Documentation

Index

Constants

View Source
const ATTR_TYPE = "type"
View Source
const VersionSeparator = "/"

Variables

View Source
var DefaultYAMLEncoding = &EncodingWrapper{
	Marshaler:   MarshalFunction(yaml.Marshal),
	Unmarshaler: UnmarshalFunction(func(data []byte, obj interface{}) error { return yaml.Unmarshal(data, obj) }),
}

Functions

func AsRawMessage added in v0.4.1

func AsRawMessage(value interface{}) (json.RawMessage, error)

func CheckSpecification added in v0.7.0

func CheckSpecification(data []byte) error

CheckSpecification checks a byte sequence to describe a valid minimum specification object.

func CompleteSpecWithType added in v0.9.0

func CompleteSpecWithType(typ string, data []byte) ([]byte, error)

func EvaluateUnstructured added in v0.3.0

func EvaluateUnstructured[T TypedObject, R TypedObjectDecoder[T]](u *UnstructuredTypedObject, types Scheme[T, R]) (T, error)

EvaluateUnstructured converts an unstructured object into a typed object. Go does not support generic methods.

func GetEncoder added in v0.3.0

func GetEncoder[T VersionedTypedObject](obj T) encoder

func GetKind added in v0.3.0

func GetKind(v TypedObject) string

func GetVersion added in v0.3.0

func GetVersion(v TypedObject) string

func IsUnknown added in v0.3.0

func IsUnknown(o TypedObject) bool

func KindNames

func KindNames[T TypedObject, R TypedObjectDecoder[T]](scheme KnownTypesProvider[T, R]) []string

func KindToVersionList added in v0.3.0

func KindToVersionList(types []string, excludes ...string) map[string]string

func KindVersion

func KindVersion(t string) (string, string)

func MarshalVersionedTypedObject added in v0.3.0

func MarshalVersionedTypedObject[T VersionedTypedObject](obj T, toe ...TypedObjectEncoder[T]) ([]byte, error)

func MustProtoType

func MustProtoType(proto interface{}) reflect.Type

func Nil added in v0.3.0

func Nil[T any]() T

func ProtoType

func ProtoType(proto interface{}) (reflect.Type, error)

func ToYAML added in v0.5.0

func ToYAML(data interface{}) ([]byte, error)

func TypeName

func TypeName(args ...string) string

func TypeNames

func TypeNames[T TypedObject, R TypedObjectDecoder[T]](scheme Scheme[T, R]) []string

func TypedObjectEqual

func TypedObjectEqual(a, b TypedObject) bool

TypedObjectEqual compares two typed objects using the unstructured type.

func TypedObjectFactory

func TypedObjectFactory(proto TypedObject) func() TypedObject

func UnstructuredTypesEqual

func UnstructuredTypesEqual(a, b *UnstructuredTypedObject) bool

UnstructuredTypesEqual compares two unstructured object.

func Validate

func Validate(o interface{}) error

Types

type Binary

type Binary []byte

Binary holds binary data which will be marshaled a base64 encoded string. If the string starts with a '!', the data is used as string byte sequence.

func (Binary) MarshalJSON

func (m Binary) MarshalJSON() ([]byte, error)

MarshalJSON returns m as the JSON encoding of m.

func (*Binary) UnmarshalJSON

func (m *Binary) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data.

type Converter added in v0.3.0

type Converter[T VersionedTypedObject, V TypedObject] interface {
	// ConvertFrom converts from an internal version into an external format.
	ConvertFrom(object T) (V, error)
	// ConvertTo converts from an external format into an internal version.
	ConvertTo(object V) (T, error)
}

type DirectDecoder

type DirectDecoder[T TypedObject] struct {
	// contains filtered or unexported fields
}

func MustNewDirectDecoder

func MustNewDirectDecoder[T TypedObject](proto T) *DirectDecoder[T]

func NewDirectDecoder

func NewDirectDecoder[T TypedObject](proto T) (*DirectDecoder[T], error)

func (*DirectDecoder[T]) CreateInstance

func (d *DirectDecoder[T]) CreateInstance() T

func (*DirectDecoder[T]) Decode

func (d *DirectDecoder[T]) Decode(data []byte, unmarshaler Unmarshaler) (T, error)

func (*DirectDecoder[T]) Encode

func (d *DirectDecoder[T]) Encode(obj T, marshaler Marshaler) ([]byte, error)

type Encoding

type Encoding interface {
	Unmarshaler
	Marshaler
}

type EncodingWrapper

type EncodingWrapper struct {
	Unmarshaler
	Marshaler
}

type FormatVersion added in v0.3.0

type FormatVersion[T VersionedTypedObject] interface {
	TypedObjectDecoder[T]
	TypedObjectEncoder[T]
}

func MustNewMultiFormatVersion added in v0.3.0

func MustNewMultiFormatVersion[T VersionedTypedObject](kind string, formats FormatVersionRegistry[T]) FormatVersion[T]

func NewConvertedVersion added in v0.3.0

func NewConvertedVersion[T VersionedTypedObject, I VersionedTypedObject, V TypedObject](converter Converter[I, V]) FormatVersion[T]

NewConvertedVersion creates a new format version for versioned typed objects, where T is the common *interface* of all types of the same type realm and I is the *internal implementation* commonly used for the various version variants of a dedicated kind of type, representing the format this format version is responsible for. Therefore, I must be subtype of T, which cannot be expressed in Go. The converter must convert between the external version, specified by the given prototype and the *internal* representation (type I) used to internally represent a set of variants as Go object.

func NewConvertedVersionByProto added in v0.3.0

func NewConvertedVersionByProto[T VersionedTypedObject, I VersionedTypedObject, V TypedObject](proto V, converter Converter[I, V]) FormatVersion[T]

func NewMultiFormatVersion added in v0.3.0

func NewMultiFormatVersion[T VersionedTypedObject](kind string, formats FormatVersionRegistry[T]) (FormatVersion[T], error)

NewMultiFormatVersion is an anonymous version, which covers a set of formats. It also accepts legacy formats with a legacy kind.

func NewSimpleVersion added in v0.3.0

func NewSimpleVersion[T VersionedTypedObject, I VersionedTypedObject]() FormatVersion[T]

NewSimpleVersion creates a new format version for versioned typed objects, where T is the common *interface* of all types of the same type realm. It creates an external version identical to the internal representation (type I). This must be a struct pointer type.

type FormatVersionRegistry added in v0.3.0

type FormatVersionRegistry[I VersionedTypedObject] interface {
	FormatVersion[I]
	Register(string, FormatVersion[I])
	KnownFormats() map[string]FormatVersion[I]
	GetFormat(name string) FormatVersion[I]
}

func NewFormatVersionRegistry added in v0.3.0

func NewFormatVersionRegistry[I VersionedTypedObject]() FormatVersionRegistry[I]

type IdentityConverter added in v0.3.0

type IdentityConverter[T TypedObject] struct{}

func (IdentityConverter[T]) ConvertFrom added in v0.3.0

func (_ IdentityConverter[T]) ConvertFrom(object T) (T, error)

func (IdentityConverter[T]) ConvertTo added in v0.3.0

func (_ IdentityConverter[T]) ConvertTo(object T) (T, error)

type InternalVersionedTypedObject added in v0.3.0

type InternalVersionedTypedObject[T VersionedTypedObject] struct {
	ObjectVersionedType
	// contains filtered or unexported fields
}

InternalVersionedTypedObject is the base type used by *internal* representations of versioned specification formats. It is used to convert from/to dedicated format versions.

func NewInternalVersionedTypedObject added in v0.3.0

func NewInternalVersionedTypedObject[T VersionedTypedObject](encoder TypedObjectEncoder[T], types ...string) InternalVersionedTypedObject[T]

type JSONMarhaler

type JSONMarhaler interface {
	MarshalJSON() ([]byte, error)
}

type KnownTypes

type KnownTypes[T TypedObject, R TypedObjectDecoder[T]] map[string]R

KnownTypes is a set of known type names mapped to appropriate object decoders.

func (KnownTypes[T, R]) Copy

func (t KnownTypes[T, R]) Copy() KnownTypes[T, R]

Copy provides a copy of the actually known types.

func (KnownTypes[T, R]) TypeNames

func (t KnownTypes[T, R]) TypeNames() []string

TypeNames return a sorted list of known type names.

type KnownTypesProvider added in v0.3.0

type KnownTypesProvider[T TypedObject, R TypedObjectDecoder[T]] interface {
	KnownTypes() KnownTypes[T, R]
}

type MarshalFunction

type MarshalFunction func(obj interface{}) ([]byte, error)

func (MarshalFunction) Marshal

func (f MarshalFunction) Marshal(obj interface{}) ([]byte, error)

type Marshaler

type Marshaler interface {
	Marshal(obj interface{}) ([]byte, error)
}

type Object

type Object interface{}

type ObjectType

type ObjectType struct {
	// Type describes the type of the object.
	Type string `json:"type"`
}

ObjectType is the data type providing serializable type information. It is an implementation of TypeInfo.

func NewObjectType

func NewObjectType(typ string) ObjectType

NewObjectType creates an ObjectType value.

func (ObjectType) GetType

func (t ObjectType) GetType() string

GetType returns the type of the object.

func (*ObjectType) SetType

func (t *ObjectType) SetType(typ string)

SetType sets the type of the object.

type ObjectTypedObject added in v0.3.0

type ObjectTypedObject = ObjectType

ObjectTypedObject is the minimal implementation of a typed object managing the type information.

func NewTypedObject added in v0.3.0

func NewTypedObject(typ string) ObjectTypedObject

type ObjectVersionedType

type ObjectVersionedType = ObjectVersionedTypedObject

ObjectVersionedType is a minimal implementation of a VersionedTypedObject. For compatibility, we keep the old not aligned type name.

type ObjectVersionedTypedObject added in v0.3.0

type ObjectVersionedTypedObject = VersionedObjectType

ObjectVersionedTypedObject is a minimal implementation of a VersionedTypedObject.

func NewVersionedTypedObject added in v0.3.0

func NewVersionedTypedObject(args ...string) ObjectVersionedTypedObject

NewVersionedTypedObject creates an ObjectVersionedType value.

type RawValue added in v0.4.1

type RawValue struct {
	json.RawMessage `json:",inline"`
}

RawValue is a json-encoded representation of a value object like a json.RawMessage, but additionally offers Getter and Setter.

func (RawValue) Copy added in v0.4.1

func (in RawValue) Copy() RawValue

func (*RawValue) GetValue added in v0.4.1

func (in *RawValue) GetValue(dest interface{}) error

GetValue returns the value as parsed object.

func (*RawValue) SetValue added in v0.4.1

func (in *RawValue) SetValue(value interface{}) error

SetValue sets the value by marshalling the given object. A passed byte slice is validated to be valid json.

type Scheme

type Scheme[T TypedObject, R TypedObjectDecoder[T]] interface {
	SchemeCommon
	KnownTypesProvider[T, R]
	TypedObjectEncoder[T]
	TypedObjectDecoder[T]

	BaseScheme() Scheme[T, R] // Go does not support an additional type parameter S Scheme[T,S] to return the correct type here

	AddKnownTypes(scheme KnownTypesProvider[T, R])
	RegisterByDecoder(typ string, decoder R) error

	ValidateInterface(object T) error
	CreateUnstructured() T
	Convert(object TypedObject) (T, error)
	GetDecoder(otype string) R
	EnforceDecode(data []byte, unmarshaler Unmarshaler) (T, error)
}

Scheme is the interface to describe a set of object types that implement a dedicated interface. As such it knows about the desired interface of the instances and can validate it. Additionally, it provides an implementation for generic unstructured objects that can be used to decode any serialized from of object candidates and provide the effective type.

func MustNewDefaultScheme

func MustNewDefaultScheme[T TypedObject, R TypedObjectDecoder[T]](protoUnstr Unstructured, acceptUnknown bool, defaultdecoder TypedObjectDecoder[T], base ...Scheme[T, R]) Scheme[T, R]

func NewDefaultScheme

func NewDefaultScheme[T TypedObject, R TypedObjectDecoder[T]](protoUnstr Unstructured, acceptUnknown bool, defaultdecoder TypedObjectDecoder[T], base ...Scheme[T, R]) (Scheme[T, R], error)

func NewScheme added in v0.3.0

func NewScheme[T TypedObject, R TypedObjectDecoder[T]](base ...Scheme[T, R]) Scheme[T, R]

type SchemeCommon added in v0.3.0

type SchemeCommon interface {
	KnownTypeNames() []string
}

type TypeGetter

type TypeGetter interface {
	// GetType returns the type of the access object.
	GetType() string
}

TypeGetter is the interface to be implemented for extracting a type.

type TypeInfo added in v0.3.0

type TypeInfo interface {
	TypeGetter
}

TypeInfo defines the accessors for type information.

type TypeScheme added in v0.3.0

type TypeScheme[T TypedObject, R TypedObjectType[T]] interface {
	Scheme[T, R]

	Register(typ R)
	GetType(name string) R
}

TypeScheme is a scheme based on Types instead of decoders.

func MustNewDefaultTypeScheme added in v0.3.0

func MustNewDefaultTypeScheme[T TypedObject, R TypedObjectType[T]](protoUnstr Unstructured, acceptUnknown bool, defaultdecoder TypedObjectDecoder[T], base ...TypeScheme[T, R]) TypeScheme[T, R]

func NewDefaultTypeScheme added in v0.3.0

func NewDefaultTypeScheme[T TypedObject, R TypedObjectType[T]](protoUnstr Unstructured, acceptUnknown bool, defaultdecoder TypedObjectDecoder[T], base ...TypeScheme[T, R]) (TypeScheme[T, R], error)

func NewTypeScheme added in v0.3.0

func NewTypeScheme[T TypedObject, R TypedObjectType[T]](base ...TypeScheme[T, R]) TypeScheme[T, R]

type TypeSetter

type TypeSetter interface {
	// SetType sets the type of abstract element
	SetType(typ string)
}

TypeSetter is the interface to be implemented for extracting a type.

type TypeVersionScheme added in v0.3.0

type TypeVersionScheme[T VersionedTypedObject, R VersionedTypedObjectType[T]] interface {
	WithKindAliases(kind ...string) TypeVersionScheme[T, R]
	Register(t R) error
	// contains filtered or unexported methods
}

TypeVersionScheme is used to register different versions for the same internal representation of a versioned typed object.

func NewTypeVersionScheme added in v0.3.0

func NewTypeVersionScheme[T VersionedTypedObject, R VersionedTypedObjectType[T]](kind string, reg VersionedTypeRegistry[T, R]) TypeVersionScheme[T, R]

type TypedObject

type TypedObject interface {
	TypeInfo
}

TypedObject defines the common interface for all kinds of typed objects.

type TypedObjectDecoder

type TypedObjectDecoder[T TypedObject] interface {
	Decode(data []byte, unmarshaler Unmarshaler) (T, error)
}

TypedObjectDecoder is able to provide an effective typed object for some serilaized form. The technical deserialization is done by an Unmarshaler.

type TypedObjectEncoder

type TypedObjectEncoder[T TypedObject] interface {
	Encode(T, Marshaler) ([]byte, error)
}

TypedObjectEncoder is able to provide a versioned representation of an effective TypedObject.

type TypedObjectType added in v0.3.0

type TypedObjectType[T TypedObject] interface {
	TypeInfo
	TypedObjectDecoder[T]
}

TypedObjectType is the interface for a type object for an TypedObject.

func NewTypedObjectTypeByDecoder added in v0.3.0

func NewTypedObjectTypeByDecoder[T TypedObject](name string, decoder TypedObjectDecoder[T]) TypedObjectType[T]

func NewTypedObjectTypeByProto added in v0.3.0

func NewTypedObjectTypeByProto[T TypedObject](name string, proto T) TypedObjectType[T]

type Unknown added in v0.3.0

type Unknown interface {
	IsUnknown() bool
}

Unknown is the interface to be implemented by representations on an unknown, but nevertheless decoded specification of a typed object.

type UnmarshalFunction

type UnmarshalFunction func(data []byte, obj interface{}) error

func (UnmarshalFunction) Unmarshal

func (f UnmarshalFunction) Unmarshal(data []byte, obj interface{}) error

type Unmarshaler

type Unmarshaler interface {
	Unmarshal(data []byte, obj interface{}) error
}

type Unstructured

type Unstructured interface {
	TypeGetter
	GetRaw() ([]byte, error)
}

Unstructured is the interface to represent generic object data for types handled by schemes.

type UnstructuredConverter

type UnstructuredConverter interface {
	ToUnstructured() (*UnstructuredTypedObject, error)
}

UnstructuredConverter converts the actual object to an UnstructuredTypedObject.

type UnstructuredMap

type UnstructuredMap map[string]interface{}

UnstructuredMap is a generic data map.

func ToUnstructuredObject

func ToUnstructuredObject(obj interface{}) (UnstructuredMap, error)

ToUnstructuredObject converts any object into a structure map.

func (UnstructuredMap) FlatCopy

func (m UnstructuredMap) FlatCopy() UnstructuredMap

FlatCopy just copies the attributes.

func (UnstructuredMap) FlatMerge

FlatMerge just joins the direct attribute set.

func (UnstructuredMap) Match added in v0.3.0

type UnstructuredTypedObject

type UnstructuredTypedObject struct {
	ObjectType `json:",inline"`
	Object     UnstructuredMap `json:"-"`
}

UnstructuredTypedObject describes a generic typed object. +kubebuilder:pruning:PreserveUnknownFields

func NewEmptyUnstructured

func NewEmptyUnstructured(ttype string) *UnstructuredTypedObject

NewEmptyUnstructured creates a new typed object without additional data.

func NewUnstructured added in v0.4.1

func NewUnstructured(ttype string, data UnstructuredMap) *UnstructuredTypedObject

NewUnstructured creates a new unstructured typed object.

func ToUnstructuredTypedObject

func ToUnstructuredTypedObject(obj interface{}) (*UnstructuredTypedObject, error)

ToUnstructuredTypedObject converts an object to an unstructured object.

func (*UnstructuredTypedObject) DeepCopy

DeepCopy is a deepcopy function, copying the receiver, creating a new UnstructuredTypedObject.

func (*UnstructuredTypedObject) DeepCopyInto

func (u *UnstructuredTypedObject) DeepCopyInto(out **UnstructuredTypedObject)

DeepCopyInto is deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (UnstructuredTypedObject) GetRaw

func (u UnstructuredTypedObject) GetRaw() ([]byte, error)

func (UnstructuredTypedObject) MarshalJSON

func (u UnstructuredTypedObject) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom json unmarshal method for a unstructured type.

func (UnstructuredTypedObject) OpenAPISchemaFormat

func (_ UnstructuredTypedObject) OpenAPISchemaFormat() string

func (UnstructuredTypedObject) OpenAPISchemaType

func (_ UnstructuredTypedObject) OpenAPISchemaType() []string

func (*UnstructuredTypedObject) SetType

func (u *UnstructuredTypedObject) SetType(ttype string)

func (*UnstructuredTypedObject) ToUnstructured

func (s *UnstructuredTypedObject) ToUnstructured() (*UnstructuredTypedObject, error)

func (*UnstructuredTypedObject) UnmarshalJSON

func (u *UnstructuredTypedObject) UnmarshalJSON(data []byte) error

UnmarshalJSON implements a custom json unmarshal method for a unstructured typed object.

type UnstructuredTypedObjectList

type UnstructuredTypedObjectList []*UnstructuredTypedObject

func (UnstructuredTypedObjectList) Copy

type UnstructuredVersionedTypedObject

type UnstructuredVersionedTypedObject struct {
	UnstructuredTypedObject `json:",inline"`
}

func NewEmptyUnstructuredVersioned

func NewEmptyUnstructuredVersioned(ttype string) *UnstructuredVersionedTypedObject

NewEmptyUnstructuredVersioned creates a new typed object without additional data.

func ToUnstructuredVersionedTypedObject

func ToUnstructuredVersionedTypedObject(obj TypedObject) (*UnstructuredVersionedTypedObject, error)

func (*UnstructuredVersionedTypedObject) DeepCopy

func (*UnstructuredVersionedTypedObject) GetKind

func (*UnstructuredVersionedTypedObject) GetVersion

func (s *UnstructuredVersionedTypedObject) GetVersion() string

func (*UnstructuredVersionedTypedObject) ToUnstructured

type Validater

type Validater interface {
	Validate() error
}

type VersionedObjectType added in v0.3.0

type VersionedObjectType ObjectType

func NewVersionedObjectType

func NewVersionedObjectType(args ...string) VersionedObjectType

func (VersionedObjectType) GetKind added in v0.3.0

func (v VersionedObjectType) GetKind() string

GetKind returns the kind of the object.

func (VersionedObjectType) GetType added in v0.3.0

func (t VersionedObjectType) GetType() string

GetType returns the type of the object.

func (VersionedObjectType) GetVersion added in v0.3.0

func (v VersionedObjectType) GetVersion() string

GetVersion returns the version of the object.

func (*VersionedObjectType) SetKind added in v0.3.0

func (v *VersionedObjectType) SetKind(kind string)

SetKind sets the kind of the object.

func (*VersionedObjectType) SetType added in v0.3.0

func (t *VersionedObjectType) SetType(typ string)

SetType sets the type of the object.

func (*VersionedObjectType) SetVersion added in v0.3.0

func (v *VersionedObjectType) SetVersion(version string)

SetVersion sets the version of the object.

type VersionedTypeInfo added in v0.3.0

type VersionedTypeInfo interface {
	TypeInfo
	GetKind() string
	GetVersion() string
}

VersionedTypeInfo in the accessor for versioned type information.

type VersionedTypeRegistry added in v0.3.0

type VersionedTypeRegistry[T VersionedTypedObject, R VersionedTypedObjectType[T]] interface {
	Register(t R)
	// contains filtered or unexported methods
}

type VersionedTypedObject

type VersionedTypedObject interface {
	TypedObject
	VersionedTypeInfo
}

VersionedTypedObject in an instance of a VersionedType.

type VersionedTypedObjectType added in v0.3.0

type VersionedTypedObjectType[T VersionedTypedObject] interface {
	VersionedTypeInfo
	TypedObjectDecoder[T]
	TypedObjectEncoder[T]
}

VersionedTypedObjectType is the interface of a type object for a versioned type.

func NewMultiFormatVersionedType added in v0.3.0

func NewMultiFormatVersionedType[T VersionedTypedObject, R VersionedTypedObjectType[T]](kind string, versions TypeVersionScheme[T, R]) (VersionedTypedObjectType[T], error)

func NewVersionedTypedObjectType added in v0.3.0

func NewVersionedTypedObjectType[T VersionedTypedObject, I VersionedTypedObject](name string) VersionedTypedObjectType[T]

func NewVersionedTypedObjectTypeByConverter added in v0.3.0

func NewVersionedTypedObjectTypeByConverter[T VersionedTypedObject, I VersionedTypedObject, V TypedObject](name string, converter Converter[I, V]) VersionedTypedObjectType[T]

func NewVersionedTypedObjectTypeByFormatVersion added in v0.3.0

func NewVersionedTypedObjectTypeByFormatVersion[T VersionedTypedObject](name string, fmt FormatVersion[T]) VersionedTypedObjectType[T]

func NewVersionedTypedObjectTypeByProtoConverter added in v0.3.0

func NewVersionedTypedObjectTypeByProtoConverter[T VersionedTypedObject, I VersionedTypedObject](name string, proto TypedObject, converter Converter[I, TypedObject]) VersionedTypedObjectType[T]

func NewVersionedTypedObjectTypeByVersion added in v0.3.0

func NewVersionedTypedObjectTypeByVersion[T VersionedTypedObject, I VersionedTypedObject](name string, version FormatVersion[I]) VersionedTypedObjectType[T]

NewVersionedTypedObjectTypeByVersion creates a new type object for versioned typed objects, where T is the common *interface* of all types of the same type realm and I is the *internal implementation* commonly used for the various version variants of a dedicated kind of type. Therefore, I must be subtype of T, which cannot be expressed in Go.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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