The yaegi executable interprets Go programs from standard input, string parameters, or files.
Execution Modes
- File Mode: Used when reading source files. Files are read entirely before parsing and evaluation, supporting forward declarations and multi-file packages. This is the default for all files unless the initial file uses a shebang (e.g.,
#!/usr/bin/env yaegi). - REPL Mode: Used for interactive sessions or when a file starts with a shebang. Code is parsed incrementally. In this mode, identifiers must be defined before use, and statements are evaluated in the global space within an implicit
main package. You do not need a package statement or a main function.
Commands
run: The default command. Executes the provided Go code.extract: Extracts information (specific implementation details depend on the version).test: Runs tests.help: Displays help information.version: Displays the current version.
If no command is provided, yaegi defaults to the run command.
# Run a one-liner string
$ yaegi -e 'println(reflect.TypeOf(fmt.Print))'
# Run an executable script with a shebang
#!/usr/bin/env yaegi
helloHandler := func(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "Hello, world!\n")
}
http.HandleFunc("/hello", helloHandler)
log.Fatal(http.ListenAndServe(":8080", nil))