Simple Analyzer is an example analyzer for the Gourmet project. It is meant to be analagous to a "Hello, World!" example program often found in software projects.
To use Simple Analyzer, there are two ways:
- Add the Github URL to your Gourmet
config.yml
file. Gourmet's example config file demonstrates how to do this. - Pass the URL as command-line option like this:
gourmet -a github.com/gourmetproject/simple_analyzer
Gourmet Analyzers are Go Plugins that implement the Gourmet Analyzer
interface. In order to
create a Gourmet Analyzer, your repository must:
-
Contain a
main.go
file at the root of the repository -
The
main.go
file must be part in themain
package. Analyzers are not standard Go libraries, but are instead Go plugins. Read the Go plugin docs for more information. -
The code in
main.go
must implement thegourmet.Analyzer
interface. Simple Analyzer does this by creating a new public type called SimpleAnalyzer, which is just an empty struct. It then declares two methods, Filter and Analyze, with SimpleAnalyzer as the pointer receiver. These two methods' signatures implement thegourmet.Analyzer
interface.NOTE: If you are not familiar with methods and pointer receivers, check this out.
NOTE: Go enforces public/private visibility through the name of the identifier itself. If the identifier starts in a capital letter, it is exported (public). If it starts with a lowercase letter, it is private. You can read more here.
-
The code in
main.go
must also implement thegourmet.Result
interface. Simple Analyzer does this by creating a new public type called SimpleResult, which is just an integer. It then declares the Key method with SimpleResult as the value receiver (not pointer receiver, since we aren't modifying the underlying SimpleResult object in the Key method).
And that's it! We now have a simple Gourmet Analyzer.