httpmiddleware

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package httpmiddleware contains HTTP middlewares.

Index

Constants

This section is empty.

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 added in v0.37.0

type AuthVerdict struct {
	Ok      bool
	Message string
}

AuthVerdict represents the result of an authentication attempt.

func Authenticated added in v0.37.0

func Authenticated() AuthVerdict

Authenticated creates a successful AuthVerdict.

func Unauthenticated added in v0.37.0

func Unauthenticated(msg string) AuthVerdict

Unauthenticated creates an AuthVerdict with a message.

type Authenticator added in v0.37.0

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

Authenticator provides an interface for authentication mechanisms.

func BasicAuth added in v0.37.0

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

BasicAuth provides an Authenticator that checks for HTTP Basic Auth.

func BearerToken added in v0.37.0

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

BearerToken provides an Authenticator that checks for Bearer tokens.

type AuthenticatorFunc added in v0.37.0

type AuthenticatorFunc func(r *http.Request) AuthVerdict

AuthenticatorFunc provides a function wrapper for Authenticator interface.

func (AuthenticatorFunc) Authenticate added in v0.37.0

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 added in v0.37.0

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 InjectLogger

func InjectLogger(lg *zap.Logger) Middleware

InjectLogger injects logger into request context.

func Instrument

func Instrument(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 added in v0.37.0

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

Token defines token config.

func (Token) Get added in v0.37.0

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

Get returns token value.

type UserCredentials added in v0.37.0

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 added in v0.37.0

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