middleware

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package middleware provides HTTP middlewares.

Index

Constants

View Source
const ThemeDefault = ThemeLight

ThemeDefault is the default color theme.

Variables

This section is empty.

Functions

func Compress

func Compress(next http.Handler) http.Handler

Compress enables brotli/gzip compression.

func NoCache

func NoCache(next http.Handler) http.Handler

NoCache disables caching.

func UserPreferences added in v0.3.0

func UserPreferences(log *slog.Logger, next http.Handler) http.Handler

UserPreferences sets the Accept-CH header and reads the user theme preference either from cookie (higher priority) or Sec-CH-Prefers-Color-Scheme (lower priority). The theme value is written to the request context and can be retrieved using GetCtxTheme.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-Prefers-Color-Scheme

Types

type Theme added in v0.3.0

type Theme int8

Theme is the preferred user color theme.

const (
	ThemeDark Theme
	ThemeLight
)

func GetCtxTheme added in v0.3.0

func GetCtxTheme(ctx context.Context) Theme

GetCtxTheme returns the color theme preferred by the client.

Jump to

Keyboard shortcuts

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