policycontroller

package
v0.1.31 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package policycontroller provides a small, reusable Observe → Decide → Act loop.

It is intentionally generic: domain packages supply concrete Observer, Evaluator, and Actuator implementations (inventory, pools, sandboxes, etc).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actuator

type Actuator[P any] interface {
	Act(ctx context.Context, plan P) error
}

Actuator applies a plan produced by an Evaluator.

type ActuatorFunc

type ActuatorFunc[P any] func(ctx context.Context, plan P) error

ActuatorFunc adapts a function into an Actuator.

func (ActuatorFunc[P]) Act

func (f ActuatorFunc[P]) Act(ctx context.Context, plan P) error

type Controller

type Controller[T any, P any] struct {
	Observer  Observer[T]
	Evaluator Evaluator[T, P]
	Actuator  Actuator[P]

	Logger *slog.Logger
}

Controller runs a single-pass (Reconcile) or looped (Run) policy controller.

func (*Controller[T, P]) Reconcile

func (c *Controller[T, P]) Reconcile(ctx context.Context) (Result[T, P], error)

Reconcile performs one Observe → Decide → (optional) Act pass.

func (*Controller[T, P]) Run

func (c *Controller[T, P]) Run(ctx context.Context, interval time.Duration) error

Run repeatedly reconciles at the given interval until ctx is cancelled. It returns nil on graceful context cancellation.

type Decision

type Decision[P any] struct {
	ShouldAct bool
	Plan      P
	Reason    string
}

Decision is the output of an evaluation pass.

If ShouldAct is false, the Controller will not call the Actuator.

type Evaluator

type Evaluator[T any, P any] interface {
	Evaluate(ctx context.Context, observed T) (Decision[P], error)
}

Evaluator compares observed state to its policy and returns a decision.

Policy is intentionally not modeled as a separate input: callers can embed policy in T, close over policy in the implementation, or compose it however they like.

type EvaluatorFunc

type EvaluatorFunc[T any, P any] func(ctx context.Context, observed T) (Decision[P], error)

EvaluatorFunc adapts a function into an Evaluator.

func (EvaluatorFunc[T, P]) Evaluate

func (f EvaluatorFunc[T, P]) Evaluate(ctx context.Context, observed T) (Decision[P], error)

type Observer

type Observer[T any] interface {
	Observe(ctx context.Context) (T, error)
}

Observer returns the current state of some managed collection/system.

type ObserverFunc

type ObserverFunc[T any] func(ctx context.Context) (T, error)

ObserverFunc adapts a function into an Observer.

func (ObserverFunc[T]) Observe

func (f ObserverFunc[T]) Observe(ctx context.Context) (T, error)

type Result

type Result[T any, P any] struct {
	Observed T
	Decision Decision[P]

	StartedAt  time.Time
	FinishedAt time.Time
	Acted      bool
}

Jump to

Keyboard shortcuts

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