parallelxl

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: 8 Imported by: 0

Documentation

Overview

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

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

Index

Examples

Constants

View Source
const ComponentClass = "parallel"

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 is a composite list that does the checks in parallel.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"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/parallelxl"
)

func main() {
	ip4 := []xlist.Resource{xlist.IPv4}
	t5ms := 5 * time.Millisecond

	cfg := parallelxl.Config{
		SkipErrors:    true,
		FirstResponse: true,
	}
	childs := []xlistd.List{
		&mockxl.List{Results: []bool{false}, ResourceList: ip4, Reason: "rbl1"},
		&mockxl.List{Results: []bool{true, false}, ResourceList: ip4, Reason: "rbl2"},
		&mockxl.List{Results: []bool{true}, Lazy: t5ms, ResourceList: ip4, Reason: "rbl3"},
		//rbl4 allways fails, but with skiperrors ignores this fail
		&mockxl.List{Fail: true, ResourceList: ip4},
	}

	//constructs parallel rbl
	rbl := parallelxl.New("test", childs, ip4, cfg)
	for i := 0; i < 4; i++ {
		resp, err := rbl.Check(context.Background(), "10.10.10.10", xlist.IPv4)
		if err != nil {
			log.Fatalln("this should not happen")
		}
		fmt.Printf("%v %v\n", resp.Result, resp.Reason)
	}

}
Output:

true rbl2
true rbl3
true rbl2
true rbl3

func New

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

New returns a new parallel component with the resources passed.

func (*List) AddChecker

func (l *List) AddChecker(list xlistd.List)

AddChecker adds a checker to the RBL

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 xlist.Checker interface.

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