Help us shape the future of Go! Take the 2026 Go Developer Survey

handler

package
v0.17.15 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package handler provides common handler types and base implementations for action handlers throughout the stackit codebase.

All action handlers share common patterns:

  • StepStatus enum for step lifecycle states
  • Cleanup() method for terminal state restoration
  • IsInteractive() method for interactive prompt support
  • NullBase struct embedding for default no-op implementations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoConfirmPromptHandler

type AutoConfirmPromptHandler struct{}

AutoConfirmPromptHandler provides a PromptHandler that always confirms. Use this when you want prompts to auto-confirm (e.g., --yes flag).

func (AutoConfirmPromptHandler) PromptConfirm

func (AutoConfirmPromptHandler) PromptConfirm(string) (bool, error)

PromptConfirm implements PromptHandler. Returns true (auto-confirm).

type Base

type Base interface {
	// Cleanup restores terminal state after the action completes.
	// Called in defer blocks to ensure cleanup on success or failure.
	// May be a no-op for non-interactive handlers.
	Cleanup()

	// IsInteractive returns true if the handler supports interactive prompts.
	// Used to determine whether to show confirmation dialogs, progress UI, etc.
	IsInteractive() bool
}

Base defines the common interface that all action handlers must implement. Embed NullBase in your handler struct to get default no-op implementations.

type NullBase

type NullBase struct{}

NullBase provides no-op implementations of the Base interface. Embed this in handler structs to inherit default implementations.

Example:

type MyNullHandler struct {
    handler.NullBase
}

// MyNullHandler now has Cleanup() and IsInteractive() implemented

func (NullBase) Cleanup

func (NullBase) Cleanup()

Cleanup implements Base. No-op for null handler.

func (NullBase) IsInteractive

func (NullBase) IsInteractive() bool

IsInteractive implements Base. Returns false for null handler.

type NullProgress

type NullProgress[Step any] struct{}

NullProgress provides a no-op implementation of ProgressHandler for any step type.

func (NullProgress[Step]) OnStep

func (NullProgress[Step]) OnStep(Step, StepStatus, string)

OnStep implements ProgressHandler. No-op for null handler.

type NullPromptHandler

type NullPromptHandler struct{}

NullPromptHandler provides a no-op implementation of PromptHandler. Returns (false, nil) for all prompts (auto-decline).

func (NullPromptHandler) PromptConfirm

func (NullPromptHandler) PromptConfirm(string) (bool, error)

PromptConfirm implements PromptHandler. Returns false (auto-decline) for null handler.

type ProgressHandler

type ProgressHandler[Step any] interface {
	// OnStep is called to report progress on a named step.
	OnStep(step Step, status StepStatus, message string)
}

ProgressHandler defines the interface for handlers that report step progress. The step parameter type varies by action, so this uses a generic Step type.

type PromptHandler

type PromptHandler interface {
	// PromptConfirm displays a confirmation prompt and returns the user's choice.
	// Returns (true, nil) to proceed, (false, nil) to cancel.
	// Returns an error if the prompt fails (e.g., terminal error).
	PromptConfirm(message string) (bool, error)
}

PromptHandler defines the interface for handlers that support confirmation prompts. Not all handlers need prompts, so this is a separate interface.

type StepStatus

type StepStatus string

StepStatus represents the lifecycle status of a step in an action. This is the standard status type used across all action handlers.

const (
	// StatusStarted indicates a step is beginning execution.
	StatusStarted StepStatus = "started"

	// StatusCompleted indicates a step finished successfully.
	StatusCompleted StepStatus = "completed"

	// StatusSkipped indicates a step was skipped (e.g., not applicable).
	StatusSkipped StepStatus = "skipped"

	// StatusFailed indicates a step encountered an error.
	StatusFailed StepStatus = "failed"
)

Step status constants - use these across all handlers for consistency.

Jump to

Keyboard shortcuts

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