reliability

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 3 Imported by: 0

README

Reliability Middleware

What it does

Applies route-level reliability policies and typed reliable endpoint behavior for idempotency, journaling, queue handoff, and response replay patterns.

How to implement

package main

import (
	"github.com/oarkflow/fh"
	"github.com/oarkflow/fh/mw/reliability"
)

func main() {
	app := fh.New()
	app.Use(reliability.New(fh.ReliabilityPolicy{
		Enabled: true,
		Journal: true,
		RequireIdempotency: true,
		ReplayResponse: true,
	}))

	app.Post("/work", func(c fh.Ctx) error { return c.JSON(fh.Map{"queued": true}) })
}

Impact

Adds durability and replay protection depending on configured policy and storage. The strongest guarantees require durable/distributed stores.

Ordering guidance

Run around unsafe operations that need reliability guarantees. Pair with body limit, idempotency, request hash, and transaction/outbox logic.

Production considerations

Use SQL/Redis/NATS/Kafka-style backends for production. Test crash recovery and duplicate request behavior.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Endpoint

func Endpoint[Req any, Res any](opt EndpointOptions[Req, Res]) fh.HandlerFunc

func New

func New(policy fh.ReliabilityPolicy) fh.HandlerFunc

New applies a core reliability policy to a route.

Types

type EndpointOptions

type EndpointOptions[Req any, Res any] struct {
	Policy    fh.ReliabilityPolicy
	Validate  func(fh.Ctx, *Req) error
	Handle    func(context.Context, fh.Ctx, Req) (Res, error)
	QueueType string
	Async     bool
}

Jump to

Keyboard shortcuts

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