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 )
The hook will return a value between 0 and 255. 0 if it succeeds. So we have these additional values here for more information.
Hook is the input structure for this library.
NewHook returns a Hook object with the provided name and params.
NewHookWithEnv returns a Hook object with the provided name, params and ExtraEnv.
NewSimpleHook returns a Hook object with just a name.
Execute tries to execute the Hook and returns a HookResult.
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.
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.
ExecuteOptional executes an optional hook, logs if it doesn't exist, and returns a printable error.
HookResult is returned by the Execute method.
String returns a printable version of the HookResult
WaitFunc is a return type for the Pipe methods. It returns the process stderr and an error, if any.