framework

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package framework provides resource lifecycle management.

Index

Constants

View Source
const (
	ResourceLockFile = "moley.lock"
)

Variables

This section is empty.

Functions

func RunWithDryRunGuard

func RunWithDryRunGuard[T any](config *Config, cb func() (T, error), defaultValue T) (T, error)

RunWithDryRunGuard runs cb unless in dry-run mode, in which case defaultValue is returned.

Types

type Config

type Config struct {
	DryRun bool
}

Config holds configuration for framework operations.

type Resource

type Resource struct {
	Handler string `json:"handler"`
	Payload any    `json:"payload"`
}

func NewResource

func NewResource(ctx context.Context, handler ResourceHandler, payload any) (*Resource, error)

func (*Resource) Hash

func (r *Resource) Hash() (string, error)

Hash returns a deterministic hash of the payload using JSON serialization.

type ResourceHandler

type ResourceHandler interface {
	Name(ctx context.Context) string
	Up(ctx context.Context, payload any) error
	Down(ctx context.Context, payload any) error
	Status(ctx context.Context, payload any) (domain.State, error)
}

type ResourceLock

type ResourceLock struct {
	Resources map[string]Resource `json:"resources"`
}

func LoadResourceLock

func LoadResourceLock() (*ResourceLock, error)

func (*ResourceLock) Add

func (rl *ResourceLock) Add(resource Resource) error

func (*ResourceLock) DiffResources

func (rl *ResourceLock) DiffResources(desiredResources []Resource) (removed, added []Resource)

DiffResources compares desired vs actual resources and returns what to remove/add.

func (*ResourceLock) Has

func (rl *ResourceLock) Has(resource Resource) bool

func (*ResourceLock) Remove

func (rl *ResourceLock) Remove(resource Resource) error

func (*ResourceLock) Save

func (rl *ResourceLock) Save() error

func (*ResourceLock) SyncResource

func (rl *ResourceLock) SyncResource(ctx context.Context, handler ResourceHandler, resource Resource) error

SyncResource syncs a single resource's state with the lockfile.

type ResourceManager

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

ResourceManager manages the lifecycle of multiple resources.

func NewResourceManager

func NewResourceManager(handlers map[string]ResourceHandler, resources []Resource) (*ResourceManager, error)

NewResourceManager creates a new resource manager.

func (*ResourceManager) Start

func (rm *ResourceManager) Start(ctx context.Context) error

Start brings resources up by comparing desired state vs previous actual state.

func (*ResourceManager) Stop

func (rm *ResourceManager) Stop(ctx context.Context) error

Stop brings all resources down.

Jump to

Keyboard shortcuts

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