httpmiddleware

package
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: Apache-2.0 Imports: 15 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

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 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