deprecation

package
v4.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package deprecation emits runtime Deprecation, Sunset, and Link headers.

The middleware follows the current HTTP header contracts for deprecation and sunset signaling while leaving response status and body behavior unchanged.

Purpose: See the package summary above. Import: `github.com/aatuh/api-toolkit/v4/middleware/deprecation`. Example: See docs/api-reference.md for package example links and docs/cookbook.md for task recipes. Errors: Constructors, parsers, and handlers return or write documented errors according to their signatures; packages with plain data types do not add hidden error channels. Concurrency: Treat configured middleware and helpers as immutable after construction; request and response values remain request-scoped unless a type documents stronger guarantees. Stability: Stable core API under VERSIONING.md and scripts/apicheck.sh. When not to use: Prefer net/http, application-owned types, or narrower helpers when this package contract is not needed.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(config Config, next http.Handler) (http.Handler, error)

Handler constructs middleware and wraps next.

Types

type Config

type Config struct {
	Disabled     bool
	DeprecatedAt time.Time
	SunsetAt     time.Time
	Links        []Link
}

Config configures runtime deprecation and sunset response headers.

type Link struct {
	URL   string
	Rel   string
	Type  string
	Title string
}

Link describes a Link header associated with deprecation or sunset policy.

type Middleware

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

Middleware emits deprecation headers without changing response behavior.

func New

func New(config Config) (*Middleware, error)

New constructs deprecation middleware.

Example
package main

import (
	"context"
	"fmt"
	"net/http"
	"net/http/httptest"
	"time"

	"github.com/aatuh/api-toolkit/v4/middleware/deprecation"
)

func main() {
	mw, err := deprecation.New(deprecation.Config{
		DeprecatedAt: time.Unix(1_700_000_000, 0),
	})
	if err != nil {
		panic(err)
	}
	handler := mw.Handler(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
		w.WriteHeader(http.StatusNoContent)
	}))

	recorder := httptest.NewRecorder()
	req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/v1/widgets", nil)
	handler.ServeHTTP(recorder, req)

	fmt.Println(recorder.Header().Get("Deprecation"))

}
Output:
@1700000000

func (*Middleware) Handler

func (m *Middleware) Handler(next http.Handler) http.Handler

Handler wraps the next handler.

Jump to

Keyboard shortcuts

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