sunset

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package sunset implements a middleware around sunset HTTP headers.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMiddleware

func NewMiddleware(opts ...Option) func(next http.Handler) http.Handler

NewMiddleware returns a new middleware that adds Sunset HTTP headers, as per RFC 8594.

Example
package main

import (
	"net/http"
	"time"

	"codeberg.org/kema/kmicro/pkg/http/middleware/sunset"
	"codeberg.org/kema/kmicro/pkg/http/router"
)

func main() {
	r := router.New()
	r.Use(sunset.NewMiddleware(
		sunset.WithSunset(time.Now().UTC()),
	))
	// curl -v localhost:8080/
	r.HandleFunc("GET /", func(w http.ResponseWriter, _ *http.Request) {
		_, _ = w.Write([]byte("Hello, World!"))
	})

	_ = http.ListenAndServe("[::]:8080", r.Compile())
}

func WrapHandler

func WrapHandler(next http.Handler, opts ...Option) http.Handler

WrapHandler wraps the next handler in the chain with Sunset HTTP headers, as per RFC 8594.

Types

type Option

type Option func(*config)

Option configures HTTP Sunset middleware.

func WithLink(link string) Option

WithLink sets the optional Link header value sent with Sunset.

func WithSunset

func WithSunset(sunset time.Time) Option

WithSunset sets the timestamp written to the Sunset response header.

Jump to

Keyboard shortcuts

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