eligibility

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package eligibility evaluates explicit action rules using supplied current facts. It has no identity, verification, catalog or network dependency.

Index

Constants

This section is empty.

Variables

View Source
var ErrConflict = errors.New("eligibility_conflict")
View Source
var ErrForbidden = errors.New("eligibility_forbidden")
View Source
var ErrRule = errors.New("invalid_eligibility_rule")
View Source
var ErrUnavailable = errors.New("eligibility_unavailable")

Functions

func Validate

func Validate(rule Rule) error

Types

type Admission

type Admission struct {
	School string
	Rules  Rules
	Facts  Facts
}

Admission evaluates independently named actions without any business-module types.

func (Admission) Check

func (a Admission) Check(ctx context.Context, subject, school, action string) (Result, error)

type CachedRules

type CachedRules struct {
	Repo Repository
	Now  func() time.Time
	// contains filtered or unexported fields
}

CachedRules keeps effective rules for at most five seconds. All local writes invalidate the cache, including writes whose commit result is unknown.

func (*CachedRules) Apply

func (c *CachedRules) Apply(ctx context.Context, in Update) (Rule, error)

func (*CachedRules) Effective

func (c *CachedRules) Effective(ctx context.Context, action, school string) (Rule, error)

func (*CachedRules) Invalidate

func (c *CachedRules) Invalidate()

type Change

type Change struct {
	ExpectedVersion string      `json:"expected_version"`
	Conditions      []Condition `json:"conditions"`
}

type Condition

type Condition string
const (
	Content    Condition = "content_access"
	Campus     Condition = "campus_eligibility"
	Phone      Condition = "phone_bound"
	Identity   Condition = "identity_verified"
	Enrollment Condition = "course_enrollment"
)

type Configuration

type Configuration struct {
	Version string                            `json:"version"`
	Rules   map[string]map[string][]Condition `json:"rules"`
}

type Defaults

type Defaults struct{}

func (Defaults) Effective

func (Defaults) Effective(_ context.Context, action, _ string) (Rule, error)

type Fact

type Fact uint8
const (
	Unknown Fact = iota
	Unsatisfied
	Satisfied
)

type Facts

type Facts interface {
	Facts(context.Context, string, string, []Condition) (map[Condition]Fact, error)
}

type Repository

type Repository interface {
	Rules
	Apply(context.Context, Update) (Rule, error)
}

type Result

type Result struct {
	Allowed     bool
	Missing     []Condition
	Unavailable []Condition
	Version     string
}

func Evaluate

func Evaluate(rule Rule, facts map[Condition]Fact) (Result, error)

type Rule

type Rule struct {
	Version    string      `json:"version"`
	Conditions []Condition `json:"conditions"`
}

type Rules

type Rules interface {
	Effective(context.Context, string, string) (Rule, error)
}

type Service

type Service struct {
	Repo Repository
	Now  func() time.Time
}

func (Service) Get

func (s Service) Get(ctx context.Context, school, action string) (Rule, error)

func (Service) Set

func (s Service) Set(ctx context.Context, actor, key, school, action string, in Change) (Rule, error)

type Update

type Update struct {
	Actor, Key, School, Action string
	Change                     Change
	At                         time.Time
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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