Documentation
¶
Overview ¶
Package middleware provides a composable, scope-aware interceptor pipeline for Trove's read/write data path. Middleware wraps the data stream — not the HTTP request — so it works identically via REST, WebSocket, or Go API.
Index ¶
- type Direction
- type Middleware
- type ReadMiddleware
- type Registration
- type Resolver
- func (r *Resolver) Register(reg Registration)
- func (r *Resolver) Registrations() []Registration
- func (r *Resolver) Remove(name string, scope Scope)
- func (r *Resolver) ResolveRead(ctx context.Context, bucket, key string) []ReadMiddleware
- func (r *Resolver) ResolveWrite(ctx context.Context, bucket, key string) []WriteMiddleware
- type Scope
- func And(scopes ...Scope) Scope
- func ForBuckets(buckets ...string) Scope
- func ForContentTypes(types ...string) Scope
- func ForKeys(patterns ...string) Scope
- func Not(scope Scope) Scope
- func Or(scopes ...Scope) Scope
- func When(fn func(ctx context.Context, bucket, key string) bool) Scope
- func WhenDesc(desc string, fn func(ctx context.Context, bucket, key string) bool) Scope
- type ScopeAnd
- type ScopeBucket
- type ScopeContentType
- type ScopeFunc
- type ScopeGlobal
- type ScopeKeyPattern
- type ScopeNot
- type ScopeOr
- type WriteMiddleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Direction ¶
type Direction int
Direction controls which data paths a middleware participates in.
const ( // DirectionRead indicates the middleware participates in downloads/gets. DirectionRead Direction = 1 << iota // DirectionWrite indicates the middleware participates in uploads/puts. DirectionWrite // DirectionReadWrite indicates the middleware participates in both paths. DirectionReadWrite = DirectionRead | DirectionWrite )
type Middleware ¶
type Middleware interface {
// Name returns the middleware identifier (e.g., "encrypt", "compress").
Name() string
// Direction returns which data paths this middleware participates in.
Direction() Direction
}
Middleware is the base interface every middleware implements. A concrete middleware implements ReadMiddleware, WriteMiddleware, or both.
type ReadMiddleware ¶
type ReadMiddleware interface {
// WrapReader wraps a reader on the download path. The info parameter
// provides metadata about the object being read.
WrapReader(ctx context.Context, r io.ReadCloser, info *driver.ObjectInfo) (io.ReadCloser, error)
}
ReadMiddleware intercepts data being read (downloaded).
type Registration ¶
type Registration struct {
// Middleware is the middleware instance.
Middleware Middleware
// Scope determines when this middleware is active.
// When nil, defaults to ScopeGlobal.
Scope Scope
// Direction overrides the middleware's own Direction() when non-zero.
// This allows registering a bidirectional middleware for only reads or writes.
Direction Direction
// Priority controls execution order. Lower values run first.
// Default is 0. Use negative values to run before default priority.
Priority int
}
Registration binds a middleware to a scope and optional direction override.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver assembles the effective middleware pipeline per-operation. It evaluates all registrations against the current context, bucket, and key, then returns an ordered pipeline sorted by priority.
func NewResolver ¶
func NewResolver() *Resolver
NewResolver creates a new pipeline resolver with LRU caching.
func (*Resolver) Register ¶
func (r *Resolver) Register(reg Registration)
Register adds a middleware registration. Thread-safe.
func (*Resolver) Registrations ¶
func (r *Resolver) Registrations() []Registration
Registrations returns a copy of all current registrations.
func (*Resolver) Remove ¶
Remove removes all registrations matching the given middleware name and scope. If scope is nil, removes all registrations with the given name.
func (*Resolver) ResolveRead ¶
func (r *Resolver) ResolveRead(ctx context.Context, bucket, key string) []ReadMiddleware
ResolveRead returns the ordered read middleware pipeline for the given operation.
func (*Resolver) ResolveWrite ¶
func (r *Resolver) ResolveWrite(ctx context.Context, bucket, key string) []WriteMiddleware
ResolveWrite returns the ordered write middleware pipeline for the given operation.
type Scope ¶
type Scope interface {
// Match returns true if the middleware should be active.
Match(ctx context.Context, bucket, key string) bool
// String returns a human-readable description for debugging.
String() string
}
Scope determines whether a middleware should be active for a given operation. Scopes are evaluated at runtime against the request context, bucket, and key.
func ForBuckets ¶
ForBuckets creates a scope matching exact bucket names.
func ForContentTypes ¶
ForContentTypes creates a scope matching MIME type prefixes.
type ScopeAnd ¶
type ScopeAnd struct {
Scopes []Scope
}
ScopeAnd requires ALL child scopes to match.
type ScopeBucket ¶
type ScopeBucket struct {
Buckets []string
}
ScopeBucket matches operations on specific bucket(s).
func (*ScopeBucket) Match ¶
func (s *ScopeBucket) Match(_ context.Context, bucket, _ string) bool
Match returns true if the bucket matches any of the configured buckets.
func (*ScopeBucket) String ¶
func (s *ScopeBucket) String() string
String returns the scope description.
type ScopeContentType ¶
type ScopeContentType struct {
Types []string
}
ScopeContentType matches by the object's content type prefix.
func (*ScopeContentType) Match ¶
func (s *ScopeContentType) Match(_ context.Context, _, key string) bool
Match checks the key extension against configured content types. For full content-type matching, use ScopeFunc with context-based lookup.
func (*ScopeContentType) String ¶
func (s *ScopeContentType) String() string
String returns the scope description.
type ScopeFunc ¶
ScopeFunc is an arbitrary predicate for custom runtime evaluation. Use this for tenant scoping, feature flags, or any runtime condition.
type ScopeGlobal ¶
type ScopeGlobal struct{}
ScopeGlobal matches every operation. This is the default when no scope is set.
func (ScopeGlobal) Match ¶
func (ScopeGlobal) Match(_ context.Context, _, _ string) bool
Match always returns true.
func (ScopeGlobal) String ¶
func (ScopeGlobal) String() string
String returns the scope description.
type ScopeKeyPattern ¶
type ScopeKeyPattern struct {
Patterns []string
}
ScopeKeyPattern matches operations on keys matching glob patterns.
func (*ScopeKeyPattern) Match ¶
func (s *ScopeKeyPattern) Match(_ context.Context, _, key string) bool
Match returns true if the key matches any of the configured patterns.
func (*ScopeKeyPattern) String ¶
func (s *ScopeKeyPattern) String() string
String returns the scope description.
type ScopeNot ¶
type ScopeNot struct {
Inner Scope
}
ScopeNot inverts a scope.
type ScopeOr ¶
type ScopeOr struct {
Scopes []Scope
}
ScopeOr requires ANY child scope to match.
type WriteMiddleware ¶
type WriteMiddleware interface {
// WrapWriter wraps a writer on the upload path. The key parameter
// identifies the object being written.
WrapWriter(ctx context.Context, w io.WriteCloser, key string) (io.WriteCloser, error)
}
WriteMiddleware intercepts data being written (uploaded).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package compress provides Zstd compression middleware for Trove.
|
Package compress provides Zstd compression middleware for Trove. |
|
Package dedup provides content-hash deduplication middleware for Trove.
|
Package dedup provides content-hash deduplication middleware for Trove. |
|
Package encrypt provides AES-256-GCM encryption middleware for Trove.
|
Package encrypt provides AES-256-GCM encryption middleware for Trove. |
|
Package scan provides content scanning middleware for Trove.
|
Package scan provides content scanning middleware for Trove. |
|
Package watermark provides invisible metadata watermarking middleware for Trove.
|
Package watermark provides invisible metadata watermarking middleware for Trove. |