contract

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: 2 Imported by: 0

README

Contract Middleware

What it does

Enforces route/API contract rules such as required headers, version compatibility, or request/response expectations depending on configuration.

How to implement

package main

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

func main() {
	app := fh.New()
	app.Use(contract.New(contract.Config{}))

	app.Get("/", func(c fh.Ctx) error {
		return c.Status(fh.StatusOK).SendString("ok")
	})
}

Impact

Improves API correctness and client compatibility. Overhead depends on the number and complexity of checks.

Ordering guidance

Run after version extraction and before handlers. In development, run stricter checks; in production, keep only required admission checks.

Production considerations

Keep contracts under source control. Add CI checks for OpenAPI/schema compatibility and route behavior.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg Config) fh.HandlerFunc

Types

type Config

type Config struct {
	Methods        []string
	ContentTypes   []string
	MaxBodyBytes   int
	RequireHeaders []string
}

Jump to

Keyboard shortcuts

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