type
Hook
Run code during a collection or global lifecycle phase.
Example
func trimTitle(ctx ridu.HookContext) error {
title, ok := ctx.Data["title"].StringValue()
if ok {
ctx.Data["title"] = store.String(strings.TrimSpace(title))
}
return nil
}Arguments
| Argument | Type | Description |
|---|---|---|
ctx | HookContext | The operation, user, values, and local API for this phase. Change Data entries before saving or Document.Values to change the response. |
Returns
Before commit, an error fails and rolls back the operation. AfterCommit errors report a committed failure.
errorHow it works
Return nil to continue or an error to stop. A pre-commit error rolls back the operation; an AfterCommit error cannot undo saved data.
Full signature
type Hook func(HookContext) errorRelated types
HookContextHookContext supplies the request, values, and local API to a collection or global hook. Change entries in Data before saving, or values in Document to change the response after saving. A Hook returns only an error.