tiered

package
v0.58.10 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package tiered is an optional visibility policy: it maps an item's level to entitlement keys and asks a Checker which ones the actor holds. It imports no billing client; a host adapts OpenRails in one expression:

checker := tiered.CheckerFunc(func(ctx context.Context, subject string, keys []string) (map[string]bool, error) {
	return client.CheckEntitlements(ctx, subject, keys, time.Time{}) // at most openrails.MaxEntitlementChecks keys
})

Index

Constants

This section is empty.

Variables

View Source
var ErrPolicy = errors.New("tiered: invalid policy")

ErrPolicy reports a policy with an unknown level or a missing required key.

Functions

func Decide

func Decide(ctx context.Context, c Checker, actor access.Actor, p Policy) (bool, error)

Decide reports whether actor may access an item under p.

func DecideAll

func DecideAll(ctx context.Context, c Checker, actor access.Actor, ps []Policy) ([]bool, error)

DecideAll decides many items with one Checker call. Anonymous actors get only Public items and never reach the Checker. Any error denies everything.

Types

type Checker

type Checker interface {
	Check(ctx context.Context, subject string, keys []string) (map[string]bool, error)
}

Checker reports which of keys the subject holds. Missing keys are not held.

type CheckerFunc

type CheckerFunc func(ctx context.Context, subject string, keys []string) (map[string]bool, error)

CheckerFunc adapts a function to Checker.

func (CheckerFunc) Check

func (f CheckerFunc) Check(ctx context.Context, subject string, keys []string) (map[string]bool, error)

type Level

type Level string

Level is an item's visibility level.

const (
	Public     Level = "public"      // anyone
	Members    Level = "members"     // membership key
	PPV        Level = "ppv"         // purchase key
	MembersPPV Level = "members_ppv" // purchase key; membership is checked only at checkout
	Premium    Level = "premium"     // premium key
)

type Policy

type Policy struct {
	Level      Level
	Membership string // e.g. "channel:{id}:membership"
	Purchase   string // e.g. "post:{billing key}"
	Premium    string // e.g. "site:premium"
}

Policy is one item's level and the host's entitlement keys for it. A purchase is ownership: a set Purchase key grants every paid level, so a buyer keeps access after the level or their membership changes.

Jump to

Keyboard shortcuts

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