-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(go): improve the Go library documentation and make minor changes…
… in API names.
- Loading branch information
Showing
6 changed files
with
175 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package yara_x | ||
|
||
import "fmt" | ||
|
||
func Example_basic() { | ||
// Compile some YARA rules. | ||
rules, _ := Compile(` | ||
rule foo { | ||
strings: | ||
$foo = "foo" | ||
condition: | ||
$foo | ||
} | ||
rule bar { | ||
strings: | ||
$bar = "bar" | ||
condition: | ||
$bar | ||
}`) | ||
|
||
// Use the compiled rules for scanning some data. | ||
matchingRules, _ := rules.Scan([]byte("foobar")) | ||
|
||
// Iterate over the matching rules. | ||
for _, r := range matchingRules { | ||
fmt.Printf("rule %s matched\n", r.Identifier()) | ||
} | ||
|
||
// Output: | ||
// rule foo matched | ||
// rule bar matched | ||
} | ||
|
||
func Example_compilerAndScanner() { | ||
// Create a new compiler. | ||
compiler := NewCompiler() | ||
|
||
// Add some rules to the compiler. | ||
err := compiler.AddSource(`rule foo { | ||
strings: | ||
$foo = "foo" | ||
condition: | ||
$foo | ||
} | ||
rule bar { | ||
strings: | ||
$bar = "bar" | ||
condition: | ||
$bar | ||
}`) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Get the compiled rules. | ||
rules := compiler.Build() | ||
|
||
// Pass the compiled rules to a scanner. | ||
scanner := NewScanner(rules) | ||
|
||
// Use the scanner for scanning some data. | ||
matchingRules, _ := scanner.Scan([]byte("foobar")) | ||
|
||
// Iterate over the matching rules. | ||
for _, r := range matchingRules { | ||
fmt.Printf("rule %s matched\n", r.Identifier()) | ||
} | ||
|
||
// Output: | ||
// rule foo matched | ||
// rule bar matched | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters