howdy/guard

Guards reject a request or provide a typed value to its continuation.

Types

A request check. Checks without a useful output return Ok(Nil).

pub type Guard(existing, value) =
  fn(context.Context(existing)) -> Result(value, service.Error)

Values

pub fn require(
  ctx: context.Context(existing),
  check: fn(context.Context(existing)) -> Result(
    value,
    service.Error,
  ),
  next: fn(value) -> response.Response(content.Content),
) -> response.Response(content.Content)

Run an endpoint guard. On success, pass its value to next; on failure, return the service error response without calling next.

use user <- guard.require(ctx, authenticated)
user_service.find(user.id) |> service.respond(ctx, user.to_json)
✨ Search Document