filter

package
v0.0.0-...-4b28c8f Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownMatchType = errors.New("unknown match type")
)

Functions

This section is empty.

Types

type Entry

type Entry struct {
	SourceName string
	Disabled   bool
	Filter     Filter
}

type Filter

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

func NewFilter

func NewFilter(matchers []Matcher) Filter

NewFilter creates a new filter to determine which downloadables should be kept based on the matchers.

func (*Filter) Filter

func (f *Filter) Filter(in []collector.Downloadable) (out []MatchedDownloadable, err error)

func (Filter) MarshalYAML

func (f Filter) MarshalYAML() (any, error)

func (*Filter) UnmarshalYAML

func (f *Filter) UnmarshalYAML(value *yaml.Node) error

type MatchType

type MatchType int
const (
	MatchTypeRequired MatchType = iota
	MatchTypeOptional
	MatchTypeExclude
	MatchTypeSufficient
	MatchTypeInvalid
)

func (MatchType) MarshalYAML

func (m MatchType) MarshalYAML() (any, error)

func (MatchType) String

func (m MatchType) String() string

func (*MatchType) UnmarshalYAML

func (m *MatchType) UnmarshalYAML(value *yaml.Node) error

type MatchedDownloadable

type MatchedDownloadable struct {
	collector.Downloadable
	Optional bool
}

type Matcher

type Matcher interface {
	Match(dl collector.Downloadable) (MatchType, bool, error)
}

Matcher is an interface that defines a method to match a downloadable to see if it should be used or not.

type MatcherWrapper

type MatcherWrapper struct {
	Matcher
	Type string
}

func (MatcherWrapper) MarshalYAML

func (m MatcherWrapper) MarshalYAML() (any, error)

func (*MatcherWrapper) UnmarshalYAML

func (m *MatcherWrapper) UnmarshalYAML(node *yaml.Node) error

type RegexMatcher

type RegexMatcher struct {
	Regex     string
	MatchType MatchType
}

RegexMatcher is a type that implements the Matcher interface to match a downloadable using a regex.

NOTE: MatchType is used to determine what to do if the regex matches. We could use negative lookaheads in the regex, but go doesn't support them. This is because they can lead to denial of service attacks.

func (*RegexMatcher) Match

Jump to

Keyboard shortcuts

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