policies

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const APPROVE = Policy("approve")
View Source
const DEFAULT = Policy("default")
View Source
const REJECT = Policy("reject")

Variables

This section is empty.

Functions

This section is empty.

Types

type Loader

type Loader interface {
	Load(context.Context) ([]URLPolicy, error)
}

Loader is used to load policies into a registry from various sources.

func StaticLoader

func StaticLoader(p []URLPolicy) Loader

StaticLoader implements the Loader interface and fills a registry with the given policies.

type Policy

type Policy string

Policy is an action name that should be applied to an URL.

type Registry

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

Registry acts as container for policies.

func NewRegistry

func NewRegistry(defaultPolicy Policy) *Registry

NewRegistry creates a new registry and sets a default policy.

func (*Registry) AddPolicy

func (r *Registry) AddPolicy(u string, policy Policy, weight int) error

AddPolicy creates a new policy given the parameters and adds it to the registry.

func (*Registry) DetermineForURL

func (r *Registry) DetermineForURL(u string) Policy

DetermineForURL returns a policy that should apply to the given URL.

func (*Registry) Load

func (r *Registry) Load(ctx context.Context, loader Loader) error

Load uses the given loader to fill the registry with policies.

func (*Registry) Policies

func (r *Registry) Policies() []URLPolicy

Policies returns a copy of all the policies inside the registry.

type URLPolicy

type URLPolicy struct {
	ID         int
	URLPattern *regexp.Regexp
	Policy     Policy
	Weight     int
}

URLPolicy is a combination of a Policy that should be applied to a given URL pattern.

Jump to

Keyboard shortcuts

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