rule

package
v8.4.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2017 License: BSD-3-Clause, BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PostValidator

type PostValidator func(context.Context) bool

PostValidator type is is introduced to implement the second part of the RFC about cache.

Q: What's the difference between this and a PreValidator? A: PreValidator runs BEFORE trying to get the cache, it cares only for the request

and if at least one PreValidator returns false then it just runs the original handler and stop there, at the other hand
a PostValidator runs if all PreValidators returns true and original handler is executed but with a response recorder,
also the PostValidator should return true to store the cached response.
Last, a PostValidator accepts a context
in order to be able to catch the original handler's response,
the PreValidator checks only for request.

If a function of type of PostValidator returns true then the (shared-always) cache is allowed to be stored.

type PreValidator

type PreValidator func(context.Context) bool

PreValidator like middleware, executes before the cache action begins, if a callback returns false then this specific cache action, with specific request, is ignored and the real (original) handler is executed instead.

I'll not add all specifications here I'll give the opportunity (public API in the httpcache package-level) to the end-user to specify her/his ignore rules too (ignore-only for now).

Each package, nethttp and fhttp should implement their own encapsulations because of different request object.

One function, accepts the request and returns false if should be denied/ignore, otherwise true. if at least one return false then the original handler will execute as it's and the whole cache action(set & get) should be ignored, it will be never go to the step of post-cache validations.

type Rule

type Rule interface {
	Claim(ctx context.Context) bool
	Valid(ctx context.Context) bool
}

Rule a superset of validators

func Chained

func Chained(rule Rule, next ...Rule) Rule

Chained returns a new rule which has more than one coming next ruleset

func Conditional

func Conditional(claimPredicate func() bool, validPredicate func() bool) Rule

Conditional returns a new rule witch has conditionals

func DefaultValidator

func DefaultValidator() Rule

DefaultValidator returns a new validator which contains the default pre and post cache validators

func Header(claim ruleset.HeaderPredicate, valid ruleset.HeaderPredicate) Rule

Header returns a new rule witch claims and execute the post validations trough headers

func HeaderClaim

func HeaderClaim(claim ruleset.HeaderPredicate) Rule

HeaderClaim returns a header rule which cares only about claiming (pre-validation)

func HeaderValid

func HeaderValid(valid ruleset.HeaderPredicate) Rule

HeaderValid returns a header rule which cares only about valid (post-validation)

func NotSatisfied

func NotSatisfied() Rule

NotSatisfied returns a rule which allows nothing

func Satisfied

func Satisfied() Rule

Satisfied returns a rule which allows anything, it's usually the last rule on chained rules if no next rule is given, but it can be used outside of a chain too as a default allow-all rule.

func Validator

func Validator(preValidators []PreValidator, postValidators []PostValidator) Rule

Validator receives the preValidators and postValidators and returns a new Validator rule

Jump to

Keyboard shortcuts

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