sequencexl

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package sequencexl provides a simple xlistd.List implementation that can be used to check in sequence on the child components.

This package is a work in progress and makes no API stability promises.

Index

Examples

Constants

View Source
const ComponentClass = "sequence"

ComponentClass registered.

Variables

This section is empty.

Functions

func Builder

func Builder(defaultCfg Config) xlistd.BuildListFn

Builder returns a builder function.

Types

type Config

type Config struct {
	FirstResponse   bool
	SkipErrors      bool
	ForceValidation bool
	Reason          string
}

Config options

type List

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

List implements a composite RBL that checks a group of lists in the order in which they were added.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/luids-io/api/xlist"
	"github.com/luids-io/xlist/pkg/xlistd"
	"github.com/luids-io/xlist/pkg/xlistd/components/mockxl"
	"github.com/luids-io/xlist/pkg/xlistd/components/sequencexl"
)

func main() {
	resources := []xlist.Resource{xlist.IPv4}

	childs := []xlistd.List{
		&mockxl.List{
			Identifier:   "rbl1",
			ResourceList: resources,
			Results:      []bool{true, false},
			Reason:       "rbl1",
		},
		&mockxl.List{
			Identifier:   "rbl2",
			ResourceList: resources,
			Fail:         true,
		},
		&mockxl.List{
			Identifier:   "rbl3",
			ResourceList: resources,
			Results:      []bool{true, false},
			Reason:       "rbl3",
		},
		&mockxl.List{
			Identifier:   "rbl4",
			ResourceList: resources,
			Results:      []bool{true, false},
			Reason:       "rbl4",
		},
	}

	//constructs sequence rbl
	rbl := sequencexl.New("test", childs, resources,
		sequencexl.Config{
			SkipErrors:    true,
			FirstResponse: true,
		})

	for i := 1; i < 5; i++ {
		resp, err := rbl.Check(context.Background(), "10.10.10.10", xlist.IPv4)
		if err != nil {
			log.Fatalln("this should not happen")
		}
		fmt.Printf("check %v: %v %v\n", i, resp.Result, resp.Reason)
	}

	// iter 1 ->
	//     check rbl1 == true -> returns true; now rbl1=false
	// iter 2 ->
	//      check rbl1 == false; now rbl1=true
	//      check rbl3 == true -> returns true; now rbl3=false
	// iter 3 ->
	//      check rbl1 == true -> returns true; now rbl1=false
	// iter 4 ->
	//      check rbl1 == false; now rbl1= true
	//      check rbl3 == false; now rbl3=true;
	//      check rbl4 == true -> returns true; now rbl4=false

}
Output:

check 1: true rbl1
check 2: true rbl3
check 3: true rbl1
check 4: true rbl4

func New

func New(id string, childs []xlistd.List, resources []xlist.Resource, cfg Config) *List

New creates a new sequence.

func (*List) Check

func (l *List) Check(ctx context.Context, name string, resource xlist.Resource) (xlist.Response, error)

Check implements xlist.Checker interface.

func (*List) Class

func (l *List) Class() string

Class implements xlistd.List interface.

func (*List) ID

func (l *List) ID() string

ID implements xlistd.List interface.

func (*List) Ping

func (l *List) Ping() error

Ping implements interface xlistd.List.

func (*List) Resources

func (l *List) Resources(ctx context.Context) ([]xlist.Resource, error)

Resources implements xlist.Checker interface.

Jump to

Keyboard shortcuts

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