hook

package
v0.19.6 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: Apache-2.0 Imports: 12 Imported by: 12

Documentation

Index

Constants

View Source
const (
	// HOOK_SUCCESS is returned when the hook worked.
	HOOK_SUCCESS = 0

	// HOOK_DOES_NOT_EXIST is returned when the hook cannot be found.
	HOOK_DOES_NOT_EXIST = -1

	// HOOK_STAT_FAILED is returned when the hook exists, but stat
	// on it fails.
	HOOK_STAT_FAILED = -2

	// HOOK_CANNOT_GET_EXIT_STATUS is returned when after
	// execution, we fail to get the exit code for the hook.
	HOOK_CANNOT_GET_EXIT_STATUS = -3

	// HOOK_INVALID_NAME is returned if a hook has an invalid name.
	HOOK_INVALID_NAME = -4

	// HOOK_VTROOT_ERROR is returned if VTROOT is not set properly.
	HOOK_VTROOT_ERROR = -5

	// HOOK_GENERIC_ERROR is returned for unknown errors.
	HOOK_GENERIC_ERROR = -6

	// HOOK_TIMEOUT_ERROR is returned when a CommandContext has its context
	// become done before the command terminates.
	HOOK_TIMEOUT_ERROR = -7
)

The hook will return a value between 0 and 255. 0 if it succeeds. So we have these additional values here for more information.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

type Hook struct {
	Name       string
	Parameters []string
	ExtraEnv   map[string]string
}

Hook is the input structure for this library.

func NewHook

func NewHook(name string, params []string) *Hook

NewHook returns a Hook object with the provided name and params.

func NewHookWithEnv

func NewHookWithEnv(name string, params []string, env map[string]string) *Hook

NewHookWithEnv returns a Hook object with the provided name, params and ExtraEnv.

func NewSimpleHook

func NewSimpleHook(name string) *Hook

NewSimpleHook returns a Hook object with just a name.

func (*Hook) Execute

func (hook *Hook) Execute() (result *HookResult)

Execute tries to execute the Hook and returns a HookResult.

func (*Hook) ExecuteAsReadPipe

func (hook *Hook) ExecuteAsReadPipe(in io.Reader) (io.Reader, WaitFunc, int, error)

ExecuteAsReadPipe will execute the hook as in a Unix pipe, reading from the provided reader. It will return: - an io.Reader to read piped data from. - a WaitFunc method to call to wait for the process to exit, that returns stderr and the Wait() error. - an error code and an error if anything fails.

func (*Hook) ExecuteAsWritePipe

func (hook *Hook) ExecuteAsWritePipe(out io.Writer) (io.WriteCloser, WaitFunc, int, error)

ExecuteAsWritePipe will execute the hook as in a Unix pipe, directing output to the provided writer. It will return: - an io.WriteCloser to write data to. - a WaitFunc method to call to wait for the process to exit, that returns stderr and the cmd.Wait() error. - an error code and an error if anything fails.

func (*Hook) ExecuteContext added in v0.8.0

func (hook *Hook) ExecuteContext(ctx context.Context) (result *HookResult)

ExecuteContext tries to execute the Hook with the given context and returns a HookResult.

func (*Hook) ExecuteOptional

func (hook *Hook) ExecuteOptional() error

ExecuteOptional executes an optional hook, logs if it doesn't exist, and returns a printable error.

type HookResult

type HookResult struct {
	ExitStatus int // HOOK_SUCCESS if it succeeded
	Stdout     string
	Stderr     string
}

HookResult is returned by the Execute method.

func (*HookResult) String

func (hr *HookResult) String() string

String returns a printable version of the HookResult

type WaitFunc

type WaitFunc func() (string, error)

WaitFunc is a return type for the Pipe methods. It returns the process stderr and an error, if any.

Jump to

Keyboard shortcuts

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