selectorxl

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 selectorxl provides a simple xlist.Checker implementation that can be used to select the component defined to the requested resource.

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

Index

Examples

Constants

View Source
const ComponentClass = "selector"

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 {
	ForceValidation bool
	Reason          string
}

Config options.

type List

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

List is a composite list that redirects requests to RBLs based on the resource type.

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

func main() {
	services := map[xlist.Resource]xlistd.List{
		xlist.IPv4: &mockxl.List{
			Identifier: "ipservice",
			Results:    []bool{true}, ResourceList: []xlist.Resource{xlist.IPv4},
			Reason: "ip4",
		},
		xlist.Domain: &mockxl.List{
			Identifier: "domainservice",
			Results:    []bool{true}, ResourceList: []xlist.Resource{xlist.Domain},
			Reason: "domain",
		}}

	rbl := selectorxl.New("test", services, selectorxl.Config{})
	resp, err := rbl.Check(context.Background(), "10.10.10.10", xlist.IPv4)
	if err != nil || !resp.Result {
		log.Fatalln("this should not happen")
	}
	fmt.Println("check 1:", resp.Reason)

	resp, err = rbl.Check(context.Background(), "www.google.com", xlist.Domain)
	if err != nil || !resp.Result {
		log.Fatalln("this should not happen")
	}
	fmt.Println("check 2:", resp.Reason)

}
Output:

check 1: ip4
check 2: domain

func New

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

New returns a new selector component.

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 xlistd.List 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