matcher

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package matcher provides a simple "rule" language that may be used inside NextDHCP plugin directives. The matcher library is based on github.com/Knetic/govaluate

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseConditions

func ParseConditions(c *caddy.Controller) (string, error)

ParseConditions parses the current dispenser block for if and if_op conditions and returns them as a single, concatenated expression string usable for govaluate.NewEvaluableExpression() and similar

Types

type ExprFunc

type ExprFunc func(args ...interface{}) (interface{}, error)

ExprFunc can be used expose functions to matcher expressions

type Matcher

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

Matcher is a DHCP message matcher

func SetupMatcher

func SetupMatcher(c *caddy.Controller, fns ...map[string]ExprFunc) (*Matcher, error)

SetupMatcher parses the current dispenser block and returns a DHCP message matcher

func SetupMatcherRemainingArgs

func SetupMatcherRemainingArgs(c *caddy.Controller, fns ...map[string]ExprFunc) (*Matcher, error)

SetupMatcherRemainingArgs creates a new DHCPv4 coniditon matcher from the remaining args available in the current dispenser line

func SetupMatcherString

func SetupMatcherString(exprString string, fns ...map[string]ExprFunc) (*Matcher, error)

SetupMatcherString creates a new DHCPv4 condition matcher form the provided string

func (*Matcher) EmptyCondition

func (m *Matcher) EmptyCondition() bool

EmptyCondition returns true if there's no condition for the matcher. In this case, any call to Match or MatchParams will return true

func (*Matcher) Match

func (m *Matcher) Match(ctx context.Context, request *dhcpv4.DHCPv4) (bool, error)

Match evaluates the expression stored in the matcher against the given request and response message

func (*Matcher) MatchParams

func (m *Matcher) MatchParams(params govaluate.Parameters) (bool, error)

MatchParams executes the parsed govaluate expression and returns the resulting boolean output. If the return value of the expression is not a boolean an error is returned

Jump to

Keyboard shortcuts

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