typed

package
v0.4.0-alpha.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MPL-2.0 Imports: 5 Imported by: 31

Documentation

Overview

Package typed generic based resource definition.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LookupExtension added in v0.3.0

func LookupExtension[I any](res resource.Resource) (I, bool)

LookupExtension looks up for the Maker interface on the resource extension. It will call Make method on it, if it has one, passing resource.Metadata and typed spec as arguments, before returning the result of Make call and attempting to cast it to the provided type parameter I. I should be an interface with a single method

The common usage is to define `Make(...) any` on extension type, and return custom type which implements I.

Types

type DeepCopyable

type DeepCopyable[T any] interface {
	DeepCopy() T
}

DeepCopyable requires a spec to have DeepCopy method which will be used during Resource copy.

type Extension added in v0.3.0

type Extension interface {
	ResourceDefinition() spec.ResourceDefinitionSpec
}

Extension is a phantom type which acts as info supplier for ResourceDefinition methods. It intantianed only during ResourceDefinition calls, so it should never contain any data which survives those calls. It can be used to provide additional method Make(*resource.Metadata, *T) any, which is used for custom interfaces. Look at LookupExtension and Maker for more details.

type Maker added in v0.3.0

type Maker[T any] interface {
	Make(*resource.Metadata, *T) any
}

Maker is an interface which can be implemented by resource extension to provide custom interfaces.

type Resource

type Resource[T DeepCopyable[T], E Extension] struct {
	// contains filtered or unexported fields
}

Resource provides a generic base implementation for resource.Resource.

func NewResource

func NewResource[T DeepCopyable[T], E Extension](md resource.Metadata, spec T) *Resource[T, E]

NewResource initializes and returns a new instance of Resource with typed spec field.

func (*Resource[T, E]) DeepCopy

func (t *Resource[T, E]) DeepCopy() resource.Resource

DeepCopy returns a deep copy of Resource.

func (*Resource[T, E]) Metadata

func (t *Resource[T, E]) Metadata() *resource.Metadata

Metadata implements Resource.

func (*Resource[T, E]) ResourceDefinition

func (t *Resource[T, E]) ResourceDefinition() spec.ResourceDefinitionSpec

ResourceDefinition implements spec.ResourceDefinitionProvider interface.

func (*Resource[T, E]) Spec

func (t *Resource[T, E]) Spec() any

Spec implements resource.Resource.

func (*Resource[T, E]) TypedSpec

func (t *Resource[T, E]) TypedSpec() *T

TypedSpec returns a pointer to spec field.

func (*Resource[T, E]) UnmarshalProto

func (t *Resource[T, E]) UnmarshalProto(md *resource.Metadata, protoBytes []byte) error

UnmarshalProto implements protobuf.Unmarshaler interface in a generic way.

UnmarshalProto requires that the spec implements the protobuf.ProtoUnmarshaller interface.

Jump to

Keyboard shortcuts

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