Documentation
¶
Index ¶
Constants ¶
const ( ExternalType = "external" CommandType = "command" )
Variables ¶
This section is empty.
Functions ¶
func ValidateCallbacks ¶
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 ¶
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, wg *sync.WaitGroup, logger interfaces.BuildLogger)
func (Callback) PreRun ¶
func (c Callback) PreRun(ctx context.Context, wg *sync.WaitGroup, logger interfaces.BuildLogger)
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 ¶
func (c *CallbackParameters) Run(ctx context.Context, logger interfaces.BuildLogger) error
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.
- logger (BuildLogger): The logger to record any logs or errors during execution.
Returns:
- error: Returns an error if validation fails or if execution of the callback fails.