Getting Started
This page walks through installing Ferret as a Go dependency, running a query, and working with the result.
Installation
These Go embedding pages target the Core development API, using Universal API v1.0.0-alpha.21 and consumable output. The website’s Standard Library version listing retains its separate release pin. The Wire example’s compatibility table lists its published dependency set for remote runtimes.
The documented checkout requires Go 1.26 or later. It includes both the reader/writer Encoding API and consumable Output API. Use this checkout as a local module replacement. From the directory containing your Go application (with its own go.mod), clone Core into a sibling directory and select the revision documented here:
git clone https://github.com/MontFerret/ferret.git ../ferret-coregit -C ../ferret-core checkout 3dcc1849b08685e9cdc71021fd2b6dd9d4003077go mod edit -replace=github.com/MontFerret/ferret/v2=../ferret-corego get github.com/MontFerret/ferret/v2
After adding the Go source below, run go mod tidy. Initialize a new application’s module first with go mod init example.com/myapp. The replacement resolves Core locally at the exact revision above; it does not depend on the version selected by an unpinned go get. Remove it when upgrading to a compatible published release.
For an existing integration, follow the consumable output migration and the Encoding API migration.
Running a query
The simplest way to execute a query is engine.Run. It compiles the source, runs it in a fresh session, and returns a one-shot output handle. Collect it to obtain owned encoded bytes.
ferret.NewAnonymousSource is convenient for one-shot queries. Use ferret.NewSource(name, content) when the source name should appear in compilation errors and debugger output. Both constructors return ferret.Source values.
Native applications normally use the root ferret package for sources, engine and session options, log levels, module contracts, parameter values, program formats, and output. Import a package under pkg only when using the specialized API owned by that package.
Compiling and reusing a plan
When the same query runs many times — with different parameters, in different goroutines, or on a schedule — compile it once and create sessions from the resulting plan:
The plan manages an internal pool of virtual machines. Sessions borrow a VM from the pool and return it on close, so creating many sessions from the same plan is efficient.
Passing parameters
Parameters let the host application inject values into a query at runtime. In FQL, parameters are referenced with the @ prefix.
Engine-level parameters apply to every session:
Session-level parameters override engine defaults for a single execution:
You can inspect which parameters a compiled query declares:
See Parameters for the full parameter API.
Handling errors
Ferret returns standard Go errors. Compilation errors include source location information:
Preparation failures are returned by Run. Once execution enters the VM, execution, encoding, hooks, and output cleanup failures are reported by Collect or Consume:
Context cancellation and timeouts work as expected:
Keep the original Run context alive until output consumption completes. A new consumption context cannot revive a canceled invocation. See Output for borrowing, cancellation, and closure.
The VM observes cancellation at structural execution boundaries rather than polling every native operation. Blocking host functions, iterators, queries, streams, and other context-aware capabilities receive this same context and must observe it while they retain control. Cancellation and deadline errors propagate to the caller and cannot be suppressed by FQL error recovery.