domain

package
v2.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: GPL-3.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LoadFromDATFunc func(m *MixMatcher, file, countryCode string, processAttr ProcessAttrFunc) error

Functions

func BatchLoadMatcher

func BatchLoadMatcher(m Matcher, entries []string, processAttr ProcessAttrFunc) error

BatchLoadMatcher loads multiple files or entries using Load.

func BatchLoadMatcherFromFiles

func BatchLoadMatcherFromFiles(m Matcher, fs []string, processAttr ProcessAttrFunc) error

BatchLoadMatcherFromFiles loads multiple files using LoadFromFile.

func Load

func Load(m Matcher, entry string, processAttr ProcessAttrFunc) error

Load loads data from a entry. If entry begin with "ext:", Load loads the file by using LoadFromFile. Else it loads the entry as a text pattern by using LoadFromText.

func LoadFromDAT

func LoadFromDAT(m *MixMatcher, file, countryCode string, processAttr ProcessAttrFunc) error

func LoadFromFile

func LoadFromFile(m Matcher, file string, processAttr ProcessAttrFunc) error

LoadFromFile loads data from a file. v2ray data file can also have multiple @attr. e.g. 'geosite.dat:cn@attr1@attr2'. Only the record with all of the @attr will be loaded.

func LoadFromText

func LoadFromText(m Matcher, s string, processAttr ProcessAttrFunc) error

func LoadFromTextFile

func LoadFromTextFile(m Matcher, file string, processAttr ProcessAttrFunc) error

func LoadFromTextReader

func LoadFromTextReader(m Matcher, r io.Reader, processAttr ProcessAttrFunc) error

func TrimDot

func TrimDot(s string) string

TrimDot trims the suffix '.'.

func UnifyDomain

func UnifyDomain(s string) string

UnifyDomain unifies domain strings. It remove the suffix "." and make sure the domain is in lower case.

Types

type Appendable

type Appendable interface {
	// Append appends v to Appendable.
	// v might be any type and nil.
	Append(v interface{})
}

type DomainMatcher

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

func NewDomainMatcher

func NewDomainMatcher() *DomainMatcher

func (*DomainMatcher) Add

func (m *DomainMatcher) Add(s string, v interface{}) error

func (*DomainMatcher) Len

func (m *DomainMatcher) Len() int

func (*DomainMatcher) Match

func (m *DomainMatcher) Match(s string) (interface{}, bool)

type DomainScanner

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

func NewUnifiedDomainScanner

func NewUnifiedDomainScanner(s string) *DomainScanner

func (*DomainScanner) PrevLabel

func (s *DomainScanner) PrevLabel() (label string, end bool)

func (*DomainScanner) PrevLabelOffset

func (s *DomainScanner) PrevLabelOffset() int

func (*DomainScanner) PrevSubDomain

func (s *DomainScanner) PrevSubDomain() (sub string, end bool)

func (*DomainScanner) Scan

func (s *DomainScanner) Scan() bool

type FullMatcher

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

func NewFullMatcher

func NewFullMatcher() *FullMatcher

func (*FullMatcher) Add

func (m *FullMatcher) Add(s string, v interface{}) error

func (*FullMatcher) Len

func (m *FullMatcher) Len() int

func (*FullMatcher) Match

func (m *FullMatcher) Match(s string) (v interface{}, ok bool)

type KeywordMatcher

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

func NewKeywordMatcher

func NewKeywordMatcher() *KeywordMatcher

func (*KeywordMatcher) Add

func (m *KeywordMatcher) Add(keyword string, v interface{}) error

func (*KeywordMatcher) Len

func (m *KeywordMatcher) Len() int

func (*KeywordMatcher) Match

func (m *KeywordMatcher) Match(s string) (v interface{}, ok bool)

type LabelNode

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

LabelNode can store dns labels efficiently.

func (*LabelNode) GetChild

func (n *LabelNode) GetChild(key string) *LabelNode

func (*LabelNode) GetValue

func (n *LabelNode) GetValue() interface{}

func (*LabelNode) IsEnd

func (n *LabelNode) IsEnd() bool

func (*LabelNode) Len

func (n *LabelNode) Len() int

func (*LabelNode) MarkAsEndNode

func (n *LabelNode) MarkAsEndNode()

func (*LabelNode) NewChild

func (n *LabelNode) NewChild(key string) *LabelNode

func (*LabelNode) StoreValue

func (n *LabelNode) StoreValue(v interface{})

type Matcher

type Matcher interface {
	// Match matches the domain s.
	// s could be an fqdn or not, and should be case insensitive.
	Match(s string) (v interface{}, ok bool)
	Len() int
	Add(pattern string, v interface{}) error
}

type MixMatcher

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

func NewMixMatcher

func NewMixMatcher(options ...MixMatcherOption) *MixMatcher

NewMixMatcher creates a MixMatcher.

func NewMixMatcherFrom

func NewMixMatcherFrom(full, domain, keyword, regex Matcher) *MixMatcher

NewMixMatcherFrom creates a MixMatcher from those sub matcher. It ok to pass nil Matcher here. MixMatcher can lazy init nil sub matcher.

func (*MixMatcher) Add

func (m *MixMatcher) Add(pattern string, v interface{}) error

func (*MixMatcher) AddElem

func (m *MixMatcher) AddElem(typ MixMatcherPatternType, pattern string, v interface{}) error

func (*MixMatcher) Len

func (m *MixMatcher) Len() int

func (*MixMatcher) Match

func (m *MixMatcher) Match(s string) (v interface{}, ok bool)

func (*MixMatcher) SetPattenTypeMap

func (m *MixMatcher) SetPattenTypeMap(typMap map[string]MixMatcherPatternType)

type MixMatcherOption

type MixMatcherOption func(mm *MixMatcher)

func WithDomainMatcher

func WithDomainMatcher(m Matcher) MixMatcherOption

func WithFullMatcher

func WithFullMatcher(m Matcher) MixMatcherOption

func WithKeywordMatcher

func WithKeywordMatcher(m Matcher) MixMatcherOption

func WithRegexpMatcher

func WithRegexpMatcher(m Matcher) MixMatcherOption

type MixMatcherPatternType

type MixMatcherPatternType uint8
const (
	MixMatcherPatternTypeDomain MixMatcherPatternType = iota
	MixMatcherPatternTypeFull
	MixMatcherPatternTypeKeyword
	MixMatcherPatternTypeRegexp
)

type ProcessAttrFunc

type ProcessAttrFunc func([]string) (v interface{}, accept bool, err error)

ProcessAttrFunc processes the additional attributions. The given []string could have a 0 length or is nil.

type RegexMatcher

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

func NewRegexMatcher

func NewRegexMatcher() *RegexMatcher

func NewRegexMatcherWithCache

func NewRegexMatcherWithCache(cap int) *RegexMatcher

func (*RegexMatcher) Add

func (m *RegexMatcher) Add(expr string, v interface{}) error

func (*RegexMatcher) Len

func (m *RegexMatcher) Len() int

func (*RegexMatcher) Match

func (m *RegexMatcher) Match(s string) (v interface{}, ok bool)

func (*RegexMatcher) ResetCache

func (m *RegexMatcher) ResetCache()

type SimpleDomainMatcher

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

SimpleDomainMatcher just like DomainMatcher, but it can not store value. It allocates less memory than DomainMatcher.

func NewSimpleDomainMatcher

func NewSimpleDomainMatcher() *SimpleDomainMatcher

func (*SimpleDomainMatcher) Add

func (m *SimpleDomainMatcher) Add(s string, _ interface{}) error

func (*SimpleDomainMatcher) Len

func (m *SimpleDomainMatcher) Len() int

func (*SimpleDomainMatcher) Match

func (m *SimpleDomainMatcher) Match(s string) (v interface{}, ok bool)

Jump to

Keyboard shortcuts

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