middleware

package
v0.9.7-patched74 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(cfg *config.Config) func(http.Handler) http.Handler

AuthMiddleware creates an authentication middleware based on config

func GetAuthMethod

func GetAuthMethod(ctx context.Context) string

GetAuthMethod retrieves the auth method from context

func GetSubject

func GetSubject(ctx context.Context) string

GetSubject retrieves the authenticated subject from context

func MetricsMiddleware

func MetricsMiddleware(m *Metrics) func(http.Handler) http.Handler

MetricsMiddleware creates a middleware that collects request metrics

func RateLimitMiddleware

func RateLimitMiddleware(cfg *config.Config, limiter *RateLimiter) func(http.Handler) http.Handler

RateLimitMiddleware creates a rate limiting middleware

Types

type ContextKey

type ContextKey string

ContextKey type for context values

const (
	// ContextKeySubject is the key for the authenticated subject
	ContextKeySubject ContextKey = "auth_subject"
	// ContextKeyAuthMethod is the key for the auth method used
	ContextKeyAuthMethod ContextKey = "auth_method"
)

type JWTClaims

type JWTClaims map[string]interface{}

JWTClaims represents standard JWT claims

type Metrics

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

Metrics collects server metrics for observability

func NewMetrics

func NewMetrics() *Metrics

NewMetrics creates a new metrics collector

func (*Metrics) GetSnapshot

func (m *Metrics) GetSnapshot() MetricsSnapshot

GetSnapshot returns a snapshot of current metrics

func (*Metrics) PrometheusFormat

func (m *Metrics) PrometheusFormat() string

PrometheusFormat returns metrics in Prometheus exposition format

func (*Metrics) RecordCacheHit

func (m *Metrics) RecordCacheHit()

RecordCacheHit records a cache hit

func (*Metrics) RecordCacheMiss

func (m *Metrics) RecordCacheMiss()

RecordCacheMiss records a cache miss

func (*Metrics) RecordEntityCreate

func (m *Metrics) RecordEntityCreate()

RecordEntityCreate records an entity creation

func (*Metrics) RecordEntityDelete

func (m *Metrics) RecordEntityDelete()

RecordEntityDelete records an entity deletion

func (*Metrics) RecordEntityList

func (m *Metrics) RecordEntityList()

RecordEntityList records an entity list operation

func (*Metrics) RecordEntityRead

func (m *Metrics) RecordEntityRead()

RecordEntityRead records an entity read

func (*Metrics) RecordEntityUpdate

func (m *Metrics) RecordEntityUpdate()

RecordEntityUpdate records an entity update

func (*Metrics) RecordGraphQuery

func (m *Metrics) RecordGraphQuery()

RecordGraphQuery records a graph query

func (*Metrics) RecordOQLQuery

func (m *Metrics) RecordOQLQuery()

RecordOQLQuery records an OQL query

func (*Metrics) RecordSearchQuery

func (m *Metrics) RecordSearchQuery()

RecordSearchQuery records a search query

type MetricsSnapshot

type MetricsSnapshot struct {
	Uptime         time.Duration
	RequestsTotal  uint64
	RequestsByPath map[string]uint64
	RequestsByCode map[int]uint64
	RequestErrors  uint64
	ActiveRequests int64
	LatencyAvgMs   float64
	LatencySumSec  float64 // total latency in seconds (for Prometheus _sum)
	LatencyCount   uint64  // total observations (for Prometheus _count)
	LatencyBuckets map[string]uint64
	EntityCreates  uint64
	EntityReads    uint64
	EntityUpdates  uint64
	EntityDeletes  uint64
	EntityLists    uint64
	CacheHits      uint64
	CacheMisses    uint64
	SearchQueries  uint64
	OQLQueries     uint64
	GraphQueries   uint64
}

MetricsSnapshot is a point-in-time snapshot of metrics

type RateLimiter

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

RateLimiter implements a fixed-window rate limiter. This allows up to 2x burst at window boundaries; a sliding-window approach would prevent that but adds complexity. Acceptable for the current use case.

func NewRateLimiter

func NewRateLimiter(cfg *config.Config) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(key string) (bool, int, time.Time)

Allow checks if a request is allowed and increments the counter

func (*RateLimiter) Stop

func (rl *RateLimiter) Stop()

Stop stops the rate limiter cleanup goroutine

Jump to

Keyboard shortcuts

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