hooks

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package hooks implements the observer pattern

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

type Hook struct {
	// contains filtered or unexported fields
}

Hook is a mechanism which supports the ability to dispatch data to arbitrary listener callbacks

func NewHook

func NewHook(db *sql.DB) *Hook

NewHook creates a new Hook

func (*Hook) After

func (h *Hook) After(callback Listener)

After registers a callback function to be invoked after the hook action occurs.

func (*Hook) Before

func (h *Hook) Before(callback Listener)

Before registers a callback function to be invoked before the hook action occurs.

func (*Hook) Dispatch

func (h *Hook) Dispatch(ctx context.Context, id string, fn func(context.Context) error) error

Dispatch invokes all listeners synchronously within a transaction. The id should uniquely identify the resource that triggers the dispatch.

type Listener

type Listener func(ctx context.Context, id string) error

Listener is a function that can listen and react to a hook event

Jump to

Keyboard shortcuts

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