crud

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Create is a constant representing create operations.
	Create = Op{"Create"}
	// Update is a constant representing update operations.
	Update = Op{"Update"}
	// Delete is a constant representing delete operations.
	Delete = Op{"Delete"}
)

Functions

This section is empty.

Types

type ActionError added in v1.3.2

type ActionError struct {
	OperationType Op     `json:"operation"`
	Kind          Kind   `json:"kind"`
	Name          string `json:"name"`
	Err           error  `json:"error"`
}

ActionError represents an error happens in performing CRUD action of an entity.

func (*ActionError) Error added in v1.3.2

func (e *ActionError) Error() string

type Actions

type Actions interface {
	Create(context.Context, ...Arg) (Arg, error)
	Delete(context.Context, ...Arg) (Arg, error)
	Update(context.Context, ...Arg) (Arg, error)
}

Actions is an interface for CRUD operations on any entity

type Arg

type Arg interface{}

Arg is an argument to a callback function.

type Event

type Event struct {
	Op     Op
	Kind   Kind
	Obj    interface{}
	OldObj interface{}
}

Event represents an event to perform an imperative operation that gets Kong closer to the target state.

func EventFromArg

func EventFromArg(arg Arg) Event

EventFromArg converts arg into Event. It panics if the type of arg is not Event.

type Kind

type Kind string

Kind represents Kind of an entity or object.

type Op

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

Op represents the type of the operation.

func (*Op) String

func (op *Op) String() string

type Registry

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

Registry can hold Kinds and their respective CRUD operations.

func (*Registry) Create

func (r *Registry) Create(ctx context.Context, kind Kind, args ...Arg) (Arg, error)

Create calls the registered create action of kind with args and returns the result and error (if any).

func (*Registry) Delete

func (r *Registry) Delete(ctx context.Context, kind Kind, args ...Arg) (Arg, error)

Delete calls the registered delete action of kind with args and returns the result and error (if any).

func (*Registry) Do

func (r *Registry) Do(ctx context.Context, kind Kind, op Op, args ...Arg) (Arg, error)

Do calls an action based on op with args and returns the result and error.

func (*Registry) Get

func (r *Registry) Get(kind Kind) (Actions, error)

Get returns actions associated with kind. An error will be returned if kind was never registered.

func (*Registry) MustRegister

func (r *Registry) MustRegister(kind Kind, a Actions)

MustRegister is same as Register but panics on error.

func (*Registry) Register

func (r *Registry) Register(kind Kind, a Actions) error

Register a kind with actions. An error will be returned if kind was previously registered.

func (*Registry) Update

func (r *Registry) Update(ctx context.Context, kind Kind, args ...Arg) (Arg, error)

Update calls the registered update action of kind with args and returns the result and error (if any).

Jump to

Keyboard shortcuts

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