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 ¶
- Constants
- func Builder(defaultCfg Config) xlistd.BuildListFn
- type Config
- type List
- func (l *List) AddChecker(list xlistd.List)
- func (l *List) Check(ctx context.Context, name string, resource xlist.Resource) (xlist.Response, error)
- func (l *List) Class() string
- func (l *List) ID() string
- func (l *List) Ping() error
- func (l *List) Resources(ctx context.Context) ([]xlist.Resource, error)
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 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 (*List) AddChecker ¶
AddChecker adds a checker to the RBL
Click to show internal directories.
Click to hide internal directories.