type

Hook

Run code during a collection or global lifecycle phase.

Example

go
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

ArgumentTypeDescription
ctxHookContextThe 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.

error

How 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

Related types

  • HookContext

    HookContext 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.

Related guides