callback

package
v1.5.8 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExternalType = "external"
	CommandType  = "command"
)

Variables

This section is empty.

Functions

func ValidateCallbacks

func ValidateCallbacks(callbacks []Callback) error

ValidateCallbacks validates a list of Callback objects by invoking their IsValid method.

Iterates through the slice of callbacks and calls IsValid on each one. If any callback returns a validation error, the function wraps it with the callback index for context and returns immediately. If all callbacks are valid or the slice is empty, returns nil.

Parameters:

  • callbacks: A slice of Callback instances to validate.

Returns:

  • error: An error if any callback fails validation, wrapped with its index; otherwise nil.

Types

type Callback

type Callback struct {
	Stage string             `yaml:"stage"`
	Pre   CallbackParameters `yaml:"pre,omitempty"`
	Post  CallbackParameters `yaml:"post,omitempty"`
}

Callback represents a stage-specific callback definition.

A callback can define separate `pre` and `post` actions to be executed before or after a specific stage.

Fields:

  • Stage: The name of the stage where the callback applies.
  • Pre: Parameters for the action to be executed before the stage.
  • Post: Parameters for the action to be executed after the stage.

func (*Callback) IsValid

func (c *Callback) IsValid() error

IsValid checks if the Callback structure is valid. It ensures that the stage name is provided and that either pre or post parameters exist. Additionally, it validates the pre and post parameters if they are set.

Returns:

  • error: An error if validation fails, otherwise nil.

func (Callback) PostRun

func (c Callback) PostRun(ctx context.Context) error

func (Callback) PreRun

func (c Callback) PreRun(ctx context.Context) error

type CallbackParameters

type CallbackParameters struct {
	Type       string   `yaml:"type"`
	Action     string   `yaml:"action"`
	Method     string   `yaml:"method,omitempty"`
	Parameters []string `yaml:"parameters,omitempty"`
}

CallbackParameters defines the details of a callback action.

Fields:

  • Type: The type of callback (e.g., "http").
  • Action: The action to be triggered (e.g., a URL or command name).
  • Method: Optional HTTP method or execution method (e.g., "GET", "POST").
  • Parameters: Optional list of arguments or parameters to pass during callback execution.

func (*CallbackParameters) IsValid

func (c *CallbackParameters) IsValid() error

IsValid checks if the CallbackParameters structure is valid. It performs type, method, action, and parameters validation.

Returns:

  • error: An error if validation fails, otherwise nil.

func (*CallbackParameters) Run

Run executes the callback based on its type (external or command). It first validates the callback parameters, then either runs an external HTTP request or a system command depending on the `Type` of the callback.

Parameters:

  • ctx (context.Context): The context for the execution, used for cancellation and timeouts.

Returns:

  • error: Returns an error if validation fails or if execution of the callback fails.

Jump to

Keyboard shortcuts

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