xlist

package
v0.0.0-...-dd22d64 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: AGPL-3.0 Imports: 8 Imported by: 25

Documentation

Overview

Package xlist defines an API to implement RBL services.

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

Index

Constants

View Source
const NeverCache = -1

NeverCache is a special value for TTL. If TTLs has this value, caches should not store the response.

Variables

View Source
var (
	ErrCanceledRequest = errors.New("xlist: canceled request")
	ErrBadRequest      = errors.New("xlist: bad request")
	ErrNotSupported    = errors.New("xlist: resource not supported")
	ErrUnavailable     = errors.New("xlist: not available")
	ErrInternal        = errors.New("xlist: internal error")
)

Some standard errors returned by interfaces.

View Source
var Resources = []Resource{IPv4, IPv6, Domain, MD5, SHA1, SHA256}

Resources is an ordered vector that constains all valid resource values. Warning: It's a variable for simplicity, Do not modify the value!.

Functions

func Canonicalize

func Canonicalize(name string, resource Resource) (string, bool)

Canonicalize returns true if the name is of the resource type and returns a string with name canonicalized to the resource type.

func DoValidation

func DoValidation(ctx context.Context, name string, resource Resource, force bool) (string, context.Context, error)

DoValidation validates the name and the resource type, and canonicalizes de name. If the resource is valid, it will return a context with a flag that indicates that future calls to the function should not validate the resource again, avoiding redundant validations. A validation can be forced if the force flag is set. If the validation is not successful, and error will be returned. This function must be used by the components that implement the interface Check and it should not be used outside of this context. To validate in any other use case, the function ValidResource must be used.

func ValidResource

func ValidResource(name string, resource Resource) bool

ValidResource returns true if the name is of the resource type.

Types

type Checker

type Checker interface {
	// Check method checks if the value encoded as string is in the list
	Check(ctx context.Context, name string, r Resource) (Response, error)
	// Resources returns an array with the resource types supported by the RBL service
	Resources(ctx context.Context) ([]Resource, error)
}

Checker is the interface for check lists.

type Resource

type Resource int

Resource stores the type of resource used by the RBLs.

const (
	IPv4 Resource = iota
	IPv6
	Domain
	MD5
	SHA1
	SHA256
)

List of valid resources at the current time.

func ClearResourceDups

func ClearResourceDups(resources []Resource, doShort bool) []Resource

ClearResourceDups returns an ordered array (if doShort) with duplicate and invalid resource items removed.

func ResourceType

func ResourceType(s string, matchOrder []Resource) (Resource, error)

ResourceType tries to guess the resource type of the string passed. Returns an error if the type can't be guessed.

func ToResource

func ToResource(s string) (Resource, error)

ToResource returns the resource type from its string representation.

func (Resource) InArray

func (r Resource) InArray(array []Resource) bool

InArray returns true if the resource value exists in the array passed as parameter.

func (Resource) IsValid

func (r Resource) IsValid() bool

IsValid returns true if the resource value is a valid.

func (Resource) MarshalJSON

func (r Resource) MarshalJSON() ([]byte, error)

MarshalJSON implements interface for struct marshalling.

func (Resource) String

func (r Resource) String() string

func (*Resource) UnmarshalJSON

func (r *Resource) UnmarshalJSON(data []byte) error

UnmarshalJSON implements interface for struct unmarshalling.

type Response

type Response struct {
	// Result is true if the value is in the list
	Result bool `json:"result"`
	// Reason stores the reason why it is the list (or not if you want)
	Reason string `json:"reason,omitempty"`
	// TTL is a number in seconds used for caching
	TTL int `json:"ttl"`
}

Response stores information about the service's responses.

Directories

Path Synopsis
grpc
check
Package check implements a xlist.Checker client and a ready to use service component.
Package check implements a xlist.Checker client and a ready to use service component.
pb
Package parallel allows multiple checks in paralell using xlist.Check interface.
Package parallel allows multiple checks in paralell using xlist.Check interface.

Jump to

Keyboard shortcuts

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