creator

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(slice []string, item string) bool

Contains checks if a string slice contains a specific item.

func DryRunActions

func DryRunActions[B any, R any](
	actions []Action[B, R],
	nilResultFactory func(action Action[B, R]) R,
	logFunc func(result *R),
) []R

DryRunActions returns pre-computed results without executing actions. This is used in dry-run mode to show what would happen without making actual changes. For each action, it uses the pre-computed action.Result, handles nil results by calling nilResultFactory, logs the result, and collects all results.

func ExecuteActions

func ExecuteActions[B any, R any](
	ctx context.Context,
	actions []Action[B, R],
	nilResultFactory func(action Action[B, R]) R,
	logFunc func(result *R),
) []R

ExecuteActions runs all actions and collects results. For each action, it calls action.Run to execute the operation, handles nil results by calling nilResultFactory, logs the result, and collects all results.

func UniqueNonEmpty

func UniqueNonEmpty(refs []string) []string

UniqueNonEmpty returns a deduplicated slice of non-empty, trimmed strings preserving the order of first occurrence. Empty and whitespace-only strings are filtered out.

Types

type Action

type Action[B any, R any] struct {
	Body   B
	Run    func(ctx context.Context, body B) *R
	Result *R
}

Action represents a planned operation with deferred execution B is the body type containing the request data R is the result type representing the outcome

func PlanActions

func PlanActions[B any, R any](
	ctx context.Context,
	bodies []B,
	planner func(ctx context.Context, body *B) Action[B, R],
) []Action[B, R]

PlanActions transforms bodies into actions using the provided planner function. The planner function is called for each body to determine what action should be taken.

func StaticAction

func StaticAction[B any, R any](body B, result R) Action[B, R]

StaticAction creates an action that always returns a pre-computed result This is used for operations that don't need actual execution, such as: - Resources that already exist - Validation errors detected during planning - Operations blocked by previous failures

type Status

type Status string

Status represents the state of a creation operation.

const (
	// StatusCreated indicates the resource was successfully created.
	StatusCreated Status = "Created"

	// StatusWouldCreate indicates the resource would be created in a real run (dry-run mode).
	StatusWouldCreate Status = "WouldCreate"

	// StatusAlreadyExists indicates the resource already exists and no action was taken.
	StatusAlreadyExists Status = "AlreadyExists"

	// StatusFailed indicates the operation failed with an error.
	StatusFailed Status = "Failed"

	// StatusMembersEnsured indicates members were successfully added to an existing resource.
	StatusMembersEnsured Status = "MembersEnsured"

	// StatusWouldEnsureMembers indicates members would be added in a real run (dry-run mode).
	StatusWouldEnsureMembers Status = "WouldEnsureMembers"

	// StatusPartiallyEnsured indicates some but not all members were successfully added.
	StatusPartiallyEnsured Status = "PartiallyEnsured"
)

Jump to

Keyboard shortcuts

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