Documentation ¶
Overview ¶
Package hookstate implements the manager and state aspects responsible for the running of hooks.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents the context under which a given hook is running.
func (*Context) Get ¶
Get unmarshals the stored value associated with the provided key into the value parameter.
func (*Context) Lock ¶
func (c *Context) Lock()
Lock acquires the state lock for this context (required for Set/Get).
func (*Context) Set ¶
Set associates value with key. The provided value must properly marshal and unmarshal with encoding/json.
func (*Context) SnapRevision ¶
SnapRevision returns the revision of the snap containing the hook.
type Handler ¶
type Handler interface { // Before is called right before the hook is to be run. Before() error // Done is called right after the hook has finished successfully. Done() error // Error is called if the hook encounters an error while running. Error(err error) error }
Handler is the interface a client must satify to handle hooks.
type HandlerGenerator ¶
HandlerGenerator is the function signature required to register for hooks.
type HookManager ¶
type HookManager struct {
// contains filtered or unexported fields
}
HookManager is responsible for the maintenance of hooks in the system state. It runs hooks when they're requested, assuming they're present in the given snap. Otherwise they're skipped with no error.
func Manager ¶
func Manager(s *state.State) (*HookManager, error)
Manager returns a new HookManager.
func (*HookManager) Ensure ¶
func (m *HookManager) Ensure() error
Ensure implements StateManager.Ensure.
func (*HookManager) Register ¶
func (m *HookManager) Register(pattern *regexp.Regexp, generator HandlerGenerator)
Register requests that a given handler generator be called when a matching hook is run, and the handler be used for the hook.
Specifically, if a matching hook is about to be run, the handler's Before() method will be called. After the hook has completed running, either the handler's Done() method or its Error() method will be called, depending on the outcome.