zip

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: BSD-3-Clause Imports: 8 Imported by: 12

README

The Zip API Object Framework

Go Report Card Latest release

This project contains the low-level object framework Zip API. It enables Kubernetes-inspired objects without the hassle of code generation.

Usage

To define your objects using the framework, simply import api.zip and declare a zip.Object along with a Spec and Status to get started.

import "api.zip"

type BookSpec struct {
	Name   string
	Author string
}

type BookState string

const (
	BookStateAvailable   = BookState("available")
	BookStateUnavailable = BookState("unavailable")
)

type BookStatus struct {
	State BookState
}

type (
	Book     = zip.Object[BookSpec, BookStatus]
	BookList = zip.ObjectList[BookSpec, BookStatus]
)

License

The Zip API Object Framework is licensed under BSD-3-Clause.

Documentation

Overview

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, The Zip API Object Framework Authors and Unikraft GmbH. Licensed under the BSD-3-Clause License (the "License"). You may not use this file except in compliance with the License.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, The Zip API Object Framework Authors and Unikraft GmbH. Licensed under the BSD-3-Clause License (the "License"). You may not use this file except in compliance with the License.

Package api.zip enables Kubernetes-inspired objects without the hassle of code generation.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, The Zip API Object Framework Authors and Unikraft GmbH. Licensed under the BSD-3-Clause License (the "License"). You may not use this file except in compliance with the License.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, The Zip API Object Framework Authors and Unikraft GmbH. Licensed under the BSD-3-Clause License (the "License"). You may not use this file except in compliance with the License.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, The Zip API Object Framework Authors and Unikraft GmbH. Licensed under the BSD-3-Clause License (the "License"). You may not use this file except in compliance with the License.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, The Zip API Object Framework Authors and Unikraft GmbH. Licensed under the BSD-3-Clause License (the "License"). You may not use this file except in compliance with the License.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, The Zip API Object Framework Authors and Unikraft GmbH. Licensed under the BSD-3-Clause License (the "License"). You may not use this file except in compliance with the License.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, The Zip API Object Framework Authors and Unikraft GmbH. Licensed under the BSD-3-Clause License (the "License"). You may not use this file except in compliance with the License.

Index

Constants

View Source
const (
	// Always rehydrate the reference object
	StoreRehydrationAlways = StoreRehydrationMode("always")

	// Only rehydratae the reference object when its Spec is nil
	StoreRehydrationSpecNil = StoreRehydrationMode("specnil")

	// Never rehydrate the reference object
	StoreRehydrationNever = StoreRehydrationMode("never")
)

Variables

Functions

func Register added in v0.1.1

func Register(schemes ...AddToScheme) error

Register accepts a slice of AddToScheme methods which are then registered against the list of global schemes.

Types

type AddToScheme added in v0.1.1

type AddToScheme func(*runtime.Scheme) error

AddToScheme is a prototype to describe the method which can be used to append a new scheme to the list of global schemes.

type ClientConfig

type ClientConfig struct {
	// contains filtered or unexported fields
}

ClientConfig contains configuration which is passed to a Zip API client.

type ClientOption

type ClientOption func(*ClientConfig) error

ClientOption is a Zip API client config option-method handler.

func WithAfter added in v0.1.1

func WithAfter(after ...OnAfter) ClientOption

WithAfter provides post-call functions which manipulate the outbound object after the client has invoked its method strategy.

func WithBefore added in v0.1.1

func WithBefore(before ...OnBefore) ClientOption

WithBefore provides pre-call functions which manipulate the inbound object before the client invokes its method strategy.

func WithStore

func WithStore[Spec, Status any](store Store, mode StoreRehydrationMode) ClientOption

WithStore sets the Abstract client's store to the specified interface implementation. An additional positional argument for the rehydration mode is used to configure when the store on the before call is used and how it manipulates the value of the reference object.

type Method

type Method[In, Out ReferenceObject] func(context.Context, In) (Out, error)

Method represents a generic API function call.

type MethodClient

type MethodClient[In, Out ReferenceObject] struct {
	// contains filtered or unexported fields
}

MethodClient is the generic Zip API client.

func (*MethodClient[In, Out]) Do

func (client *MethodClient[In, Out]) Do(ctx context.Context, req In) (Out, error)

Do implements MethodStrategy.

type MethodStrategy

type MethodStrategy[In, Out ReferenceObject] interface {
	// Do performs the request by invoking the provided generic Method.
	Do(context.Context, In) (Out, error)
}

MethodStrategy is a generic method handler which standardizes implementation of a client such that the action performed on a specific endpoint for a given input type In which returns a known output type Out is consistently implemented.

func NewMethodClient

func NewMethodClient[In, Out ReferenceObject](
	ctx context.Context,
	fn Method[In, Out],
	opts ...ClientOption,
) (
	MethodStrategy[In, Out],
	error,
)

NewMethodClient instantiates a new Zip API method client.

type Object

type Object[Spec, Status any] struct {
	metav1.TypeMeta `json:",inline"`

	// Standard object's metadata.
	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

	// Specification of the desired behavior of the Object.
	Spec Spec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`

	// Most recently observed status of the Object.
	Status Status `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}

Object represents a generic low-level Kubernetes-inspired object which contains information about the object type, its metadata, a specification which is used to describe the object and its current status.

func (*Object[Spec, Status]) DeepCopy

func (in *Object[Spec, Status]) DeepCopy() *Object[Spec, Status]

DeepCopy copies the receiver, creating a new Object.

func (*Object[Spec, Status]) DeepCopyInto

func (in *Object[Spec, Status]) DeepCopyInto(out *Object[Spec, Status])

DeepCopyInto is a deepcopy function, copying the receiver, writing into out.

func (Object[_, _]) DeepCopyObject

func (in Object[_, _]) DeepCopyObject() runtime.Object

DeepCopyObject implements runtime.Object.

func (*Object[_, _]) GetObjectKind

func (obj *Object[_, _]) GetObjectKind() schema.ObjectKind

GetObjectKind implements runtime.Object.

func (*Object[_, _]) GroupVersionKind

func (obj *Object[_, _]) GroupVersionKind() schema.GroupVersionKind

GroupVersionKind returns the API version and kind of the object reference.

func (*Object[_, _]) Reference

func (obj *Object[_, _]) Reference() (string, error)

Reference implements Referencable

func (*Object[_, _]) SetGroupVersionKind

func (obj *Object[_, _]) SetGroupVersionKind(gvk schema.GroupVersionKind)

SetGroupVersionKind sets the API version and kind of the object reference.

type ObjectList

type ObjectList[Spec, Status any] struct {
	metav1.TypeMeta `json:",inline"`

	// Standard object's metadata.
	metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

	// Items contains the list of machines.
	Items []Object[Spec, Status] `json:"items" protobuf:"bytes,2,rep,name=items"`
}

ObjectList represents a list of Objects.

func (*ObjectList[Spec, Status]) DeepCopy

func (list *ObjectList[Spec, Status]) DeepCopy() *ObjectList[Spec, Status]

DeepCopy copies the receiver, creating a new ObjectList.

func (*ObjectList[Spec, Status]) DeepCopyInto

func (in *ObjectList[Spec, Status]) DeepCopyInto(out *ObjectList[Spec, Status])

DeepCopyInto copies the receiver, writing into out. in must be non-nil.

func (*ObjectList[_, _]) DeepCopyObject

func (list *ObjectList[_, _]) DeepCopyObject() runtime.Object

DeepCopyObject implements runtime.Object.

func (*ObjectList[_, _]) GetObjectKind

func (list *ObjectList[_, _]) GetObjectKind() schema.ObjectKind

GetObjectKind implements runtime.Object.

func (*ObjectList[_, _]) GroupVersionKind

func (list *ObjectList[_, _]) GroupVersionKind() schema.GroupVersionKind

GroupVersionKind returns the API version and kind of the object reference

func (*ObjectList[_, _]) Reference

func (list *ObjectList[_, _]) Reference() (string, error)

Reference implements Referencable.

func (*ObjectList[_, _]) SetGroupVersionKind

func (list *ObjectList[_, _]) SetGroupVersionKind(gvk schema.GroupVersionKind)

SetGroupVersionKind sets the API version and kind of the object reference

type OnAfter

OnAfter is a prototype for a function that can be called on a referencable object after it has been returned by the client.

type OnBefore

type OnBefore func(context.Context, ReferenceObject) (any, error)

OnBefore is a prototype for a function that can be called on a referencable object before it is invoked by the client.

type Referencable

type Referencable interface {
	Reference() (string, error)
}

Referencable is an interface for allowing the object to return a unique reference for lookups.

type ReferenceObject

type ReferenceObject interface {
	Referencable
	runtime.Object
}

ReferenceObject combines the low-level Kubernetes-centric runtime.Object and the Zip API Referencable to allow mutable, copyable objects to be referenced at runtime.

type Store

type Store storage.Interface

Store is an alias for the underlying implementation.

type StoreRehydrationMode added in v0.1.2

type StoreRehydrationMode string

StoreRehydrationMode is a switch that dictates how the store's before call is used to manipulate the

type Stream

type Stream[In ReferenceObject, Out any] func(context.Context, In) (chan Out, chan error, error)

Stream represents a generic stream-enabled API function call.

type StreamClient

type StreamClient[In ReferenceObject, Out any] struct {
	// contains filtered or unexported fields
}

StreamClient provides the interface for connecting to a remote service which returns a stream.

func (*StreamClient[In, Out]) Channel

func (client *StreamClient[In, Out]) Channel(
	ctx context.Context,
	req In,
) (
	chan Out,
	chan error,
	error,
)

Channel implements StreamStrategy

type StreamStrategy

type StreamStrategy[In ReferenceObject, Out any] interface {
	// Channel performs the request with the provide input In and returns a
	// channel which allows returning a stream of content.  Any issues from the
	// stream itself will be propagated back through the error channel.
	// Initialization errors are returned through the standard error.
	Channel(context.Context, In) (chan Out, chan error, error)
}

StreamMethodStrategy is a generic handler which standardizes the implementation of a streaming client which performs actions on an input In which resolves to a stream (implemented as a Go channel) Out.

func NewStreamClient

func NewStreamClient[In ReferenceObject, Out any](
	ctx context.Context,
	fn Stream[In, Out],
	opts ...ClientOption,
) (
	StreamStrategy[In, Out],
	error,
)

NewStreamClient instantiates a new stream-enable client for the given stream provider.

Jump to

Keyboard shortcuts

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