Documentation
¶
Overview ¶
Package entitlements defines provider-neutral contracts and helpers for tenant plan, feature, and quota enforcement.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidCheck reports a malformed tenant, feature, or amount. ErrInvalidCheck = errors.New("invalid entitlement check") // ErrNilStore reports that no store was configured. ErrNilStore = errors.New("entitlement store is required") )
Functions ¶
func Middleware ¶
func Middleware(service Service, extract TenantExtractor, feature Feature) func(http.Handler) http.Handler
Middleware enforces a feature before invoking the next HTTP handler.
Types ¶
type Decision ¶
type Decision struct {
Allowed bool
Feature Feature
Reason DecisionReason
Used int64
Limit int64
}
Decision is safe to send to logs or metrics because it excludes tenant IDs, customer IDs, subscription IDs, and other provider-owned identifiers.
type DecisionReason ¶
type DecisionReason string
DecisionReason is a low-cardinality entitlement decision reason.
const ( // ReasonAllowed means the feature or quota check passed. ReasonAllowed DecisionReason = "allowed" // ReasonFeatureDenied means the tenant plan does not include the feature. ReasonFeatureDenied DecisionReason = "feature_denied" // ReasonQuotaExceeded means usage crossed the configured quota limit. ReasonQuotaExceeded DecisionReason = "quota_exceeded" )
type Feature ¶
type Feature string
Feature names an application-owned capability or quota dimension.
type Quota ¶
type Quota struct {
Limit int64
}
Quota describes an optional usage limit for a feature.
type Service ¶
Service enforces plan features and quotas through a Store.
func (Service) Consume ¶
func (s Service) Consume(ctx context.Context, tenantID string, feature Feature, amount int64) (Decision, error)
Consume increments usage for feature and reports whether the tenant remains within the configured quota. Features without a positive quota are allowed when the plan includes the feature.
type Store ¶
type Store interface {
PlanForTenant(ctx context.Context, tenantID string) (Plan, error)
IncrementUsage(ctx context.Context, tenantID string, feature Feature, amount int64) (Usage, error)
}
Store loads tenant plans and persists usage counters.
type TenantExtractor ¶
TenantExtractor returns the tenant ID for an HTTP request.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package entitlementstest provides reusable contract tests for entitlements stores.
|
Package entitlementstest provides reusable contract tests for entitlements stores. |