github.com/netdata/go.d.plugin@v0.58.1/pkg/matcher/doc_test.go (about)

     1  // SPDX-License-Identifier: GPL-3.0-or-later
     2  
     3  package matcher_test
     4  
     5  import "github.com/netdata/go.d.plugin/pkg/matcher"
     6  
     7  func ExampleNew_string_format() {
     8  	// create a string matcher, which perform full text match
     9  	m, err := matcher.New(matcher.FmtString, "hello")
    10  	if err != nil {
    11  		panic(err)
    12  	}
    13  	m.MatchString("hello")       // => true
    14  	m.MatchString("hello world") // => false
    15  }
    16  
    17  func ExampleNew_glob_format() {
    18  	// create a glob matcher, which perform wildcard match
    19  	m, err := matcher.New(matcher.FmtString, "hello*")
    20  	if err != nil {
    21  		panic(err)
    22  	}
    23  	m.MatchString("hello")       // => true
    24  	m.MatchString("hello world") // => true
    25  	m.MatchString("Hello world") // => false
    26  }
    27  
    28  func ExampleNew_simple_patterns_format() {
    29  	// create a simple patterns matcher, which perform wildcard match
    30  	m, err := matcher.New(matcher.FmtSimplePattern, "hello* !*world *")
    31  	if err != nil {
    32  		panic(err)
    33  	}
    34  	m.MatchString("hello")        // => true
    35  	m.MatchString("hello world")  // => true
    36  	m.MatchString("Hello world")  // => false
    37  	m.MatchString("Hello world!") // => false
    38  }
    39  
    40  func ExampleNew_regexp_format() {
    41  	// create a regexp matcher, which perform wildcard match
    42  	m, err := matcher.New(matcher.FmtRegExp, "[0-9]+")
    43  	if err != nil {
    44  		panic(err)
    45  	}
    46  	m.MatchString("1")  // => true
    47  	m.MatchString("1a") // => true
    48  	m.MatchString("a")  // => false
    49  }