values

package
v0.0.0-...-e2109fa Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MatchLogic

type MatchLogic int
const (
	MatchValuesOr  MatchLogic = 1
	MatchValuesAnd MatchLogic = 2
)

type Matcher

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

Matcher is used for strings match ,and it supports regex, wildcard. A Matcher includes several strings, regex patterns, wildcard patterns for building, and then accept one string for matching. The methods of Matcher are all not thread-safe.

func NewMatcher

func NewMatcher(options ...Option) *Matcher

NewMatcher accept options for match action. Set WithMatchCaseSensitive for if case-sensitive when do matching. Set WithMatchLogic for match action with "or" and "and" logic operation.

func (*Matcher) Append

func (m *Matcher) Append(pattern string) error

Append will insert a pattern into Matcher. The type of pattern is auto recognized in follow rules:

/^regex$/ the pattern start and end with "/" means it's a regex.

%wild*card% the pattern start and end with "%" means it's a wildcard.

string otherwise, it's a string.

func (*Matcher) Empty

func (m *Matcher) Empty() bool

Empty returns the pattern in Matcher if empty.

func (*Matcher) Match

func (m *Matcher) Match(value string) bool

Match will do match input value param with pattern in Matcher with options.

type Option

type Option func(*Matcher)

func WithMatchCaseSensitive

func WithMatchCaseSensitive(sensitive bool) Option

WithMatchCaseSensitive defines if case-sensitive when do matching. The default value is false.

func WithMatchLogic

func WithMatchLogic(logic MatchLogic) Option

WithMatchLogic defines match logic between patterns in Matcher. It's effective when regex or wildcard is not empty. The normal string matching will not use this option. The default value is MatchValuesOr.

Jump to

Keyboard shortcuts

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