resource

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExists   = errors.New("resource already exists")
	ErrNotFound = errors.New("resource not found")
)

Functions

This section is empty.

Types

type Event

type Event[T Resource] struct {
	Type    EventType
	Payload T
}

Event represents an event in the lifecycle of a resource

type EventType

type EventType string

EventType identifies the type of event

const (
	CreatedEvent EventType = "created"
	UpdatedEvent EventType = "updated"
	DeletedEvent EventType = "deleted"
)

type ID

type ID struct {
	Serial uint
	Kind   Kind
}

ID is a unique identifier for a pug resource.

func NewID

func NewID(kind Kind) ID

func (ID) GetID added in v0.2.0

func (id ID) GetID() ID

GetID allows ID to be accessed via an interface value.

func (ID) GetKind added in v0.2.0

func (id ID) GetKind() Kind

GetKind allows Kind to be accessed via an interface value.

func (ID) String

func (id ID) String() string

type Kind

type Kind int
const (
	Global Kind = iota
	Module
	Workspace
	Plan
	Task
	TaskGroup
	Log
	LogAttr
	State
	StateResource
)

func (Kind) String

func (k Kind) String() string

type Publisher

type Publisher[T any] interface {
	Publish(EventType, T)
}

type Resource

type Resource interface {
	// GetID retrieves the unique identifier for the resource.
	GetID() ID
	// GetKind retrieves the kind of resource.
	GetKind() Kind
	// String is a human-readable identifier for the resource. Not necessarily
	// unique across pug.
	String() string
}

Resource is a unique pug entity

type Table

type Table[T any] struct {
	// contains filtered or unexported fields
}

Table is an in-memory database table that emits events upon changes.

func NewTable

func NewTable[T any](pub Publisher[T]) *Table[T]

func (*Table[T]) Add

func (t *Table[T]) Add(id ID, row T)

func (*Table[T]) Delete

func (t *Table[T]) Delete(id ID)

func (*Table[T]) Get

func (t *Table[T]) Get(id ID) (T, error)

func (*Table[T]) List

func (t *Table[T]) List() []T

func (*Table[T]) Update

func (t *Table[T]) Update(id ID, updater func(existing T) error) (T, error)

Jump to

Keyboard shortcuts

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