Documentation ¶
Overview ¶
Package typed generic based resource definition.
Index ¶
- func LookupExtension[I any](res resource.Resource) (I, bool)
- type DeepCopyable
- type Extension
- type Maker
- type Resource
- func (t *Resource[T, E]) DeepCopy() resource.Resource
- func (t *Resource[T, E]) Metadata() *resource.Metadata
- func (t *Resource[T, E]) ResourceDefinition() spec.ResourceDefinitionSpec
- func (t *Resource[T, E]) Spec() any
- func (t *Resource[T, E]) TypedSpec() *T
- func (t *Resource[T, E]) UnmarshalProto(md *resource.Metadata, protoBytes []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LookupExtension ¶ added in v0.3.0
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. Type Parameter 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
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]) ResourceDefinition ¶
func (t *Resource[T, E]) ResourceDefinition() spec.ResourceDefinitionSpec
ResourceDefinition implements spec.ResourceDefinitionProvider interface.