hook

package
Version: v3.0.0-...-1c69814 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: LGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ControlHookCleanup

type ControlHookCleanup func()

ControlHookCleanup defines a function used to remove a control hook.

type ControlProcessor

type ControlProcessor func(sc ServiceControl, args ...interface{}) error

ControlProcessor defines a function that is run when a specified control point is reached in the service business logic. The function receives the service instance so internal state can be inspected, plus for any arguments passed to the currently executing service function.

type ServiceControl

type ServiceControl interface {
	RegisterControlPoint(name string, controller ControlProcessor) ControlHookCleanup
}

ServiceControl instances allow hooks to be registered for execution at the specified point of execution. The control point name can be a function name or a logical execution point meaningful to the service. If name is "", the hook for the currently executing function is executed. Returns a function which can be used to remove the hook.

type TestService

type TestService struct {
	ServiceControl
	// Hooks to run when specified control points are reached in the service business logic.
	ControlHooks map[string]ControlProcessor
}

func (*TestService) ProcessControlHook

func (s *TestService) ProcessControlHook(hookName string, sc ServiceControl, args ...interface{}) error

ProcessControlHook retrieves the ControlProcessor for the specified hook name and runs it, returning any error. Use it like this to invoke a hook registered for some arbitrary control point:

if err := n.ProcessControlHook("foobar", <serviceinstance>, <somearg1>, <somearg2>); err != nil {
    return err
}

func (*TestService) ProcessFunctionHook

func (s *TestService) ProcessFunctionHook(sc ServiceControl, args ...interface{}) error

ProcessFunctionHook runs the ControlProcessor for the current function, returning any error. Use it like this:

if err := n.ProcessFunctionHook(<serviceinstance>, <somearg1>, <somearg2>); err != nil {
    return err
}

func (*TestService) RegisterControlPoint

func (s *TestService) RegisterControlPoint(hookName string, controller ControlProcessor) ControlHookCleanup

RegisterControlPoint assigns the specified controller to the named hook. If nil, any existing controller for the hook is removed. hookName is the name of a function on the service or some arbitrarily named control point.

Jump to

Keyboard shortcuts

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