middleware

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package middleware holds HTTP middleware shared by every service that runs on the common httpserver. Nothing here is domain-specific: Observer is applied by the server to all traffic, and Auth is a reusable per-route guard.

Index

Constants

This section is empty.

Variables

View Source
var (
	// RequestDuration stores HTTP request execution duration data to be served by the Prometheus metrics service.
	RequestDuration = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "http_request_duration_seconds",
			Help:    "Duration of HTTP requests in seconds",
			Buckets: prometheus.DefBuckets,
		},
		[]string{"method", "path", "status_code"},
	)
	// RequestCount is an incremental counter measuring the total request count for each route and response status code.
	RequestCount = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "http_request_count_total",
			Help: "Total number of HTTP requests",
		},
		[]string{"method", "path", "status_code"},
	)
)

Functions

func Auth

Auth returns middleware that resolves the credential in the X-Auth-Password header to a user ID via authn, injects it into the request context, and rejects the request with 401 if resolution fails. It is deliberately per-route: services wrap the handlers that need protection and leave probes and metrics open.

func Observer

func Observer(next http.Handler) http.Handler

Observer wraps an http.Handler with request logging and Prometheus metrics. The httpserver applies it once around the whole router, so every service — orders today, the notifier next — gets identical observability for free rather than opting in per route.

Types

This section is empty.

Jump to

Keyboard shortcuts

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