server

package
v0.0.48 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: GPL-3.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultXApiKeyHeaderName string = "X-Api-Key"
)

Variables

View Source
var (
	ErrNotAuthorized = errors.New("unauthorized")
)

Functions

func AuthenticationMiddleware added in v0.0.45

func AuthenticationMiddleware(authFunc UserAuthenticationFunc) func(http.Handler) http.Handler

AuthenticationMiddleware is a middleware that authenticates the user through the given UserAuthenticationFunc and sets the user in the context.

func LoggingMiddleware

func LoggingMiddleware(next http.Handler) http.Handler

LoggingMiddleware is a middleware that logs HTTP requests and responses. It extracts the request body and logs it. It also logs the request and response details.

func TelemetryMiddleware added in v0.0.38

func TelemetryMiddleware(mux *http.ServeMux) http.Handler

TelemetryMiddleware is a middleware that wraps the provided http.ServeMux with OpenTelemetry instrumentation. It instruments the ServeMux with the otelhttp.NewHandler function and enables logging for all requests handled by the ServeMux.

Types

type ApiKeyMap added in v0.0.45

type ApiKeyMap struct {
	// contains filtered or unexported fields
}

ApiKeyMap stores hashed API keys grouped by a deterministic lookup token.

It uses a bucket index to reduce the amount of bcrypt comparisons performed on each request while still using bcrypt for the final key verification.

func NewApiKeyMapFromHashedMap added in v0.0.45

func NewApiKeyMapFromHashedMap(m map[string]User) (ApiKeyMap, error)

NewApiKeyMapFromHashedMap creates a new ApiKeyMap from a map of hashed API keys to users.

func NewApiKeyMapFromPlainMap added in v0.0.45

func NewApiKeyMapFromPlainMap(m map[string]User) (ApiKeyMap, error)

NewApiKeyMapFromPlainMap creates a new ApiKeyMap from a plain map of API keys to users.

type User added in v0.0.45

type User interface {
	UserID() string
	UserData() map[string]any
}

User represents a user.

func AuthenticatedUserFromContext added in v0.0.45

func AuthenticatedUserFromContext(ctx context.Context) User

AuthenticatedUserFromContext returns the authenticated user from the context.

type UserAuthenticationFunc added in v0.0.45

type UserAuthenticationFunc func(r *http.Request) (User, error)

UserAuthenticationFunc is a function that authenticates a user based on the provided request.

func MultipleUserApiKeyAuthenticationFunc added in v0.0.45

func MultipleUserApiKeyAuthenticationFunc(authData ApiKeyMap, headerName string) UserAuthenticationFunc

MultipleUserApiKeyAuthenticationFunc authenticates the user based on the provided map of API keys to users.

func SingleUserApiKeyAuthenticationFunc added in v0.0.45

func SingleUserApiKeyAuthenticationFunc(apiKey, headerName string, user User) UserAuthenticationFunc

SingleUserApiKeyAuthenticationFunc authenticates the user based on the provided API key and user.

Jump to

Keyboard shortcuts

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