rules

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoTerminatorDefined = errors.New("no terminator defined")
	ErrUnknownTerminator   = errors.New("no terminator with the given name is known")
	ErrUnknownFilterMethod = errors.New("no filter with the given name is known")
	ErrNoInitiatorDefined  = errors.New("no initiator defined")
	ErrUnknownInitiator    = errors.New("no initiator with the given name is known")
)
View Source
var (
	ErrNoParser     = errors.New("no parser available for given type")
	ErrTypeMismatch = errors.New("param has a different type")
)
View Source
var ErrAmbiguousParamCount = errors.New("the supplied number of arguments does not match the expected one")

Functions

func FloatP

func FloatP(value float64) *float64

func IntP

func IntP(value int) *int

func Parse

func Parse(rule string, target interface{}) error

Parse takes a raw rule and parses it into the given target instance currently only SingleResponsePipeline and Check are supported for parsing

func StringP

func StringP(value string) *string

func ValidateParameterCount

func ValidateParameterCount(params []Param, expected int) error

Types

type CIDR

type CIDR struct {
	*net.IPNet
}

func MustParseCIDR

func MustParseCIDR(cidr string) *CIDR

func ParseCIDR

func ParseCIDR(cidr string) (*CIDR, error)

func (*CIDR) UnmarshalText

func (c *CIDR) UnmarshalText(text []byte) (err error)

type Call added in v0.8.0

type Call struct {
	Module string  `parser:"(@Module'.')?"`
	Name   string  `parser:"@Ident"`
	Params []Param `parser:"'(' @@? ( ',' @@ )*')'"`
}

type ChainedResponsePipeline added in v0.8.0

type ChainedResponsePipeline struct {
	FilterChain *Filters `parser:"@@*"`
	Response    []Call   `parser:"'=>' @@ ('=>' @@)*"`
}

ChainedResponsePipeline describes how requests are handled that expect a chain of response handlers e.g. DHCP where one handler might set the IP, one sets the default gateway, one sets the DNS servers and so on A ChainedResponsePipeline is defined as an optional chain of Filters like: filter1() -> filter2() and a chain of Response handlers while at least one has to be present // a full chain might look like so: MatchMAC(`00:06:7C:.*`) => IP(3.3.6.6) => Router(1.2.3.4) => DNS(1.2.3.4, 4.5.6.7)

func (*ChainedResponsePipeline) Filters added in v0.8.0

func (p *ChainedResponsePipeline) Filters() []Call

type Check

type Check struct {
	Initiator  *Call    `parser:"@@"`
	Validators *Filters `parser:"( '=>' @@)?"`
}

type CheckScript

type CheckScript struct {
	Checks []Check `parser:"@@*"`
}

type FilteredPipeline added in v0.8.0

type FilteredPipeline interface {
	Filters() []Call
}

type Filters

type Filters struct {
	Chain []Call `parser:"@@ ('->' @@)*"`
}

type Param

type Param struct {
	String *string  `parser:"@String | @RawString"`
	Int    *int     `parser:"| @Int"`
	Float  *float64 `parser:"| @Float"`
	IP     net.IP   `parser:"| @IP"`
	CIDR   *CIDR    `parser:"| @CIDR"`
}

func (Param) AsCIDR

func (p Param) AsCIDR() (*CIDR, error)

func (Param) AsFloat

func (p Param) AsFloat() (float64, error)

func (Param) AsIP

func (p Param) AsIP() (net.IP, error)

func (Param) AsInt

func (p Param) AsInt() (int, error)

func (Param) AsString

func (p Param) AsString() (string, error)

type SingleResponsePipeline added in v0.8.0

type SingleResponsePipeline struct {
	FilterChain *Filters `parser:"@@*"`
	Response    *Call    `parser:"'=>' @@"`
}

SingleResponsePipeline describes how requests are handled that expect single response e.g. HTTP or DNS requests A SingleResponsePipeline is defined as an optional chain of Filters like: filter1() -> filter2() and a Response which determines how the request should be handled e.g. http.Status(204) a full chain might look like so: GET() -> Header("Accept", "application/json") -> http.Status(200).

func (*SingleResponsePipeline) Filters added in v0.8.0

func (p *SingleResponsePipeline) Filters() []Call

Jump to

Keyboard shortcuts

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