hook

package
v0.1.25 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTimeout

func GetTimeout() time.Duration

GetTimeout returns the current per-hook execution timeout.

func Remove

func Remove(id ID)

Remove unregisters the hook with the given id. Unknown or zero ids are ignored. When the last hook is removed the registry snapshot becomes nil again so the no-hook path stays zero-cost.

func Reset

func Reset()

Reset clears all registered hooks and restores the default hook timeout.

func RunAfter

func RunAfter(reg *Registry, key string, value []byte, committed bool, writeErr error)

RunAfter runs ObserverAfter hooks with the write outcome.

func RunBefore

func RunBefore(reg *Registry, key string, value []byte) ([]byte, error)

RunBefore runs Abort, Transform, and Observer hooks (in that order) against the incoming value and returns the final transformed value.

func SetTimeout

func SetTimeout(d time.Duration)

SetTimeout sets the per-hook execution timeout. Values <= 0 disable timeouts (hooks then run with panic recovery only).

Types

type Abort

type Abort func(key string, value []byte) error

Abort vetoes a write when it returns an error (fail-closed).

type ID

type ID uint64

ID uniquely identifies a registered hook. The zero value is never assigned.

func AddAbort

func AddAbort(h Abort) ID

func AddObserver

func AddObserver(h Observer) ID

func AddObserverAfter

func AddObserverAfter(h ObserverAfter) ID

func AddTransform

func AddTransform(h Transform) ID

type Observer

type Observer func(key string, value []byte)

Observer inspects the post-Transform value before the write (fail-open).

type ObserverAfter

type ObserverAfter func(key string, value []byte, committed bool, writeErr error)

ObserverAfter inspects the write outcome after commit (fail-open).

type Registry

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

Registry is an immutable snapshot of all registered hooks.

func Snapshot

func Snapshot() *Registry

Snapshot returns the current hook registry, or nil when no hooks are registered, keeping the no-hook path zero-cost.

func (*Registry) LenAborts

func (r *Registry) LenAborts() int

func (*Registry) LenAfters

func (r *Registry) LenAfters() int

func (*Registry) LenObservers

func (r *Registry) LenObservers() int

func (*Registry) LenTransforms

func (r *Registry) LenTransforms() int

type Transform

type Transform func(key string, value []byte) (newValue []byte, err error)

Transform rewrites the value before the write (fail-closed; chained in registration order).

Jump to

Keyboard shortcuts

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