hooks

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package hooks is a small FHIR intercept SPI for HAIStack.

HAPI's interceptor bus has dozens of pointcuts. This package keeps four:

  • Incoming — HTTP request after routing, before the handler runs
  • PreStorage — core write path, after validation/id assignment, before persist
  • PostCommit — core write path, after the write session commits
  • Outgoing — HTTP response, before a resource envelope is serialized

Register Func values on a Registry with On, then wire the same Registry into core.ResourceServiceConfig.Hooks and http.Config.Hooks (runtime.Builder.WithHooks does both). Hooks run in registration order. Incoming, pre-storage, and outgoing errors abort the request; post-commit errors are ignored so a successful write is not reported as failure.

Do not add more pointcuts here. Extend by registering another Func on one of these four, or by wrapping HTTP middleware for transport concerns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action names the FHIR interaction that triggered the hook.

const (
	ActionRead        Action = "read"
	ActionCreate      Action = "create"
	ActionUpdate      Action = "update"
	ActionPatch       Action = "patch"
	ActionDelete      Action = "delete"
	ActionSearch      Action = "search"
	ActionHistory     Action = "history"
	ActionTransaction Action = "transaction"
	ActionBatch       Action = "batch"
	ActionOperation   Action = "operation"
	ActionMetadata    Action = "metadata"
)

type Event

type Event struct {
	Point        Point
	Action       Action
	ResourceType string
	ID           string
	Operation    string
	Resource     *types.ResourceEnvelope
	Previous     *types.ResourceEnvelope
}

Event is the payload delivered to a hook. Resource is mutable on pre-storage and outgoing so a hook can replace or annotate it.

type Func

type Func func(ctx context.Context, event *Event) error

Func is one intercept callback.

type Hooks

type Hooks interface {
	Run(ctx context.Context, point Point, event *Event) error
}

Hooks runs the four intercept stages. Registry implements it.

type Point

type Point string

Point is one of the four intercept stages.

const (
	Incoming   Point = "incoming"
	PreStorage Point = "pre-storage"
	PostCommit Point = "post-commit"
	Outgoing   Point = "outgoing"
)

type Registry

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

Registry holds Func values for the four points.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty hook registry.

func (*Registry) On

func (r *Registry) On(point Point, fn Func) error

On registers fn for point. Unknown points are rejected.

func (*Registry) Run

func (r *Registry) Run(ctx context.Context, point Point, event *Event) error

Run invokes registered funcs for point in registration order.

Jump to

Keyboard shortcuts

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