go-vitess.v1: gopkg.in/src-d/go-vitess.v1/vt/hook Index | Files

package hook

import "gopkg.in/src-d/go-vitess.v1/vt/hook"

Index

Package Files

hook.go

Constants

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.

type Hook Uses

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

Hook is the input structure for this library.

func NewHook Uses

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

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

func NewHookWithEnv Uses

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 Uses

func NewSimpleHook(name string) *Hook

NewSimpleHook returns a Hook object with just a name.

func (*Hook) Execute Uses

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

Execute tries to execute the Hook and returns a HookResult.

func (*Hook) ExecuteAsReadPipe Uses

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 Uses

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) ExecuteOptional Uses

func (hook *Hook) ExecuteOptional() error

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

type HookResult Uses

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

HookResult is returned by the Execute method.

func (*HookResult) String Uses

func (hr *HookResult) String() string

String returns a printable version of the HookResult

type WaitFunc Uses

type WaitFunc func() (string, error)

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

Package hook imports 10 packages (graph) and is imported by 18 packages. Updated 2019-06-13. Refresh now. Tools for package owners.