httpmiddleware

package
v0.45.0 Latest Latest
Warning

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

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

Documentation

Overview

Package httpmiddleware contains HTTP middlewares.

Index

Constants

View Source
const ProfileHeader = "X-Oteldb-Profile"

ProfileHeader, when set to a truthy value ("1", "true", "yes", "on") on a request, turns on EXPLAIN ANALYZE for that query: the storage fetch operators record a profiled tree with per-node timing and I/O counters. This matches the X-Oteldb-Profile convention the storage cluster read path uses between peers.

Variables

This section is empty.

Functions

func Wrap

func Wrap(h http.Handler, middlewares ...Middleware) http.Handler

Wrap handler using given middlewares.

Types

type AuthVerdict

type AuthVerdict struct {
	Ok      bool
	Message string
}

AuthVerdict represents the result of an authentication attempt.

func Authenticated

func Authenticated() AuthVerdict

Authenticated creates a successful AuthVerdict.

func Unauthenticated

func Unauthenticated(msg string) AuthVerdict

Unauthenticated creates an AuthVerdict with a message.

type Authenticator

type Authenticator interface {
	Authenticate(r *http.Request) AuthVerdict
}

Authenticator provides an interface for authentication mechanisms.

func BasicAuth

func BasicAuth(users []UserCredentials) (Authenticator, error)

BasicAuth provides an Authenticator that checks for HTTP Basic Auth.

func BearerToken

func BearerToken(tokens []Token) (Authenticator, error)

BearerToken provides an Authenticator that checks for Bearer tokens.

type AuthenticatorFunc

type AuthenticatorFunc func(r *http.Request) AuthVerdict

AuthenticatorFunc provides a function wrapper for Authenticator interface.

func (AuthenticatorFunc) Authenticate

func (f AuthenticatorFunc) Authenticate(r *http.Request) AuthVerdict

Authenticate implements Authenticator interface.

type Metrics

type Metrics interface {
	TracerProvider() trace.TracerProvider
	MeterProvider() metric.MeterProvider
	TextMapPropagator() propagation.TextMapPropagator
}

Metrics wraps TracerProvider and MeterProvider.

type Middleware

type Middleware = func(http.Handler) http.Handler

Middleware is a net/http middleware.

func Auth

func Auth(sets []Authenticator, onError func(w http.ResponseWriter, req *http.Request, msg string)) Middleware

Auth provides a middleware that tries multiple authenticators in sequence.

func Explain added in v0.43.0

func Explain() Middleware

Explain enables EXPLAIN ANALYZE for requests carrying the X-Oteldb-Profile header. It installs a storage profile collector into the request context and, after the handler runs, renders the fetch-operator tree to the context logger.

It is zero-overhead for requests without the header: the storage operators' profile.Begin is a no-op when no collector is in the context, so the normal query path makes no extra timing reads or allocations. Install it after InjectLogger so the rendered tree reaches the request logger.

func InjectLogger

func InjectLogger(lg *zap.Logger) Middleware

InjectLogger injects logger into request context.

func Instrument

func Instrument(endpoint, serviceName string, find RouteFinder, m Metrics) Middleware

Instrument setups otelhttp.

func LogRequests

func LogRequests(find RouteFinder) Middleware

LogRequests logs incoming requests using context logger.

type OgenRoute

type OgenRoute interface {
	Name() string
	OperationID() string
}

OgenRoute is a generic ogen route type.

type OgenServer

type OgenServer[R OgenRoute] interface {
	FindPath(method string, u *url.URL) (r R, _ bool)
}

OgenServer is a generic ogen server type.

type RouteFinder

type RouteFinder func(method string, u *url.URL) (OgenRoute, bool)

RouteFinder finds Route by given URL.

func MakeRouteFinder

func MakeRouteFinder[R OgenRoute, S OgenServer[R]](server S) RouteFinder

MakeRouteFinder creates RouteFinder from given server.

type Token

type Token struct {
	Token     string `json:"token" yaml:"token"`
	TokenFile string `json:"token_file" yaml:"token_file"`
}

Token defines token config.

func (Token) Get

func (t Token) Get() (string, error)

Get returns token value.

type UserCredentials

type UserCredentials struct {
	User         string `json:"user" yaml:"user"`
	Password     string `json:"password" yaml:"password"`
	PasswordFile string `json:"password_file" yaml:"password_file"`
}

UserCredentials holds username and password.

func (UserCredentials) GetPassword

func (u UserCredentials) GetPassword() (string, error)

GetPassword returns password value.

Jump to

Keyboard shortcuts

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