Skip to Content

gofasta console

Launches yaegi  — a Go interpreter — in the current project directory, with your project on the import path. Useful for poking at a service, running an ad-hoc query, or trying out a library API without writing a throwaway main() and rebuilding.

Usage

gofasta console

Run it from the project root. The command takes no flags of its own.

Prerequisite: yaegi

Yaegi is a third-party interpreter, not a dependency of the CLI, so it is not installed for you. Install it once:

go install github.com/traefik/yaegi/cmd/yaegi@latest

The command looks up yaegi on $PATH and fails immediately with an install hint if it isn’t there. If you just installed it and the lookup still fails, ~/go/bin (or $GOBIN) is not on your PATH — see Installation → Troubleshooting for the one-time fix.

Session

$ gofasta console Starting gofasta console (yaegi)... Type Go code interactively. Press Ctrl+D to exit. > import "myapp/app/models" > u := models.User{FirstName: "Alice"} > u.FirstName "Alice"

Press Ctrl+D to exit. Ctrl+C is forwarded to the interpreter, so it interrupts the statement being evaluated rather than killing the terminal session out from under you.

What the interpreter can and cannot do

Yaegi interprets Go rather than compiling it, and that boundary is where surprises live:

  • cgo is unavailable. Any package that requires cgo will not load. This includes some database drivers — notably the cgo build of SQLite.
  • unsafe is restricted, so packages reaching into memory layout directly may fail to import.
  • Generics support depends on the yaegi release you installed; older versions choke on generic code that compiles fine with go build.

When yaegi cannot handle something, write it into a small file and use go run instead. The console is for exploration, not a substitute for the compiler.

Not available in --json mode

The console is a REPL: stdin is your keyboard and stdout is the interpreter’s prompts, neither of which can be represented as a structured document. Invoking it with --json therefore fails immediately with the INTERACTIVE_ONLY error code rather than launching a process whose output an agent could not parse:

$ gofasta console --json { "code": "INTERACTIVE_ONLY", "message": "console is an interactive REPL and cannot run in --json mode", "hint": "this command requires an interactive terminal and cannot run in --json / headless mode; drop --json or invoke a non-interactive equivalent" }

Agents and CI runners can pattern-match on that code and skip the command instead of hanging on a process waiting for input. For inspection that is scriptable, reach for gofasta inspect, gofasta routes, or the gofasta debug family — all of which emit structured output.

Last updated on