REPL

In this guide, you will learn about the following topics:

  • Starting the REPL session
  • Evaluating expressions and statements
  • Multi-line input
  • Importing packages and using your app's code
  • Working with models and database queries
  • REPL commands reference
  • Command history and exiting

Overview

The Nimbus REPL extends the standard Go REPL with application-aware features. When you run it from your app root, it uses your project's go.mod context, so you can import and evaluate your app's packages, models, and services. The REPL is useful during development for quick experimentation, debugging, and data exploration.

Starting the REPL session

Start the REPL from your app directory using the Nimbus CLI:

nimbus repl

You'll see a prompt where you can type Go code and press Enter to execute it:

gore version 0.6.1  :help for help
gore> 

The output appears immediately, creating a fast feedback loop for testing and exploration.

Evaluating expressions

You can evaluate any Go expression. The result is printed automatically:

gore> 1 + 2
3

gore> len("hello")
5

gore> []string{"a", "b", "c"}[1]
"b"

gore> map[string]int{"x": 1, "y": 2}["y"]
2

Statements and variables

Declare variables and run statements. Variables persist across the session:

gore> x := 42
42

gore> y := "world"
"world"

gore> x * 2
84

gore> fmt.Sprintf("Hello, %s", y)
"Hello, world"

Use :import fmt first if fmt is not yet imported.

Multi-line input

The REPL supports multi-line input. When a line is incomplete (e.g. unclosed brace or parenthesis), the prompt changes to ..... and you can continue typing on the next line:

gore> func greet(name string) string {
.....     return "Hello, " + name
..... }
""

gore> greet("Nimbus")
"Hello, Nimbus"

Press Enter on an empty line to execute the block, or continue typing to add more lines.

Importing packages

Use the :import command to load packages. Standard library and your app's packages are available:

gore> :import fmt
gore> fmt.Println("Hello from REPL")
Hello from REPL
17
2
nil

gore> :import encoding/json
gore> b, _ := json.Marshal(map[string]any{"name": "Nimbus"})
gore> string(b)
`{"name":"Nimbus"}`

Using your app's models

Import your app's packages to work with models and types. Replace myapp with your module name from go.mod:

gore> :import myapp/app/models
gore> todo := models.Todo{Title: "Learn REPL", Done: false}
gore> todo.Title
"Learn REPL"

You can inspect struct types, create instances, and pass them to functions.

Database queries

To query the database, import the database package, your config, and models. The database must be migrated and reachable. Connect first, then run queries:

gore> :import github.com/CodeSyncr/nimbus/database
gore> :import myapp/config
gore> :import myapp/app/models
gore> config.Load()
gore> database.ConnectWithConfig(database.ConnectConfig{
.....     Driver: config.Database.Driver,
.....     DSN:    config.Database.DSN,
..... })
gore> var todos []models.Todo
gore> database.Get().Find(&todos)
gore> len(todos)
3

Ensure .env is loaded (e.g. via godotenv in config) and migrations have been run.

Inspecting types and documentation

Use :type to print an expression's type and :doc to view documentation:

gore> :type todos
[]models.Todo

gore> :doc database.Get
func Get() *gorm.DB
    Get returns the default database connection.

gore> :doc fmt.Println
func Println(a ...any) (n int, err error)
    Println formats using the default formats for its operands...

REPL commands reference

All commands start with a colon:

Command Description
:import <pkg>Import a package
:type <expr>Print expression type
:printShow accumulated source code
:write [file]Write source to file
:clearClear accumulated code
:doc <expr|pkg>Show documentation
:helpList all commands
:quitExit the session

Command history

The REPL saves your command history. Use the arrow keys to navigate:

  • — Previous command
  • — Next command
  • Ctrl+R — Reverse search (type to filter history)

History is stored in ~/.gore/history (or $GORE_HOME/history).

Exiting the session

Exit using :quit or Ctrl-D:

gore> :quit

The REPL does not auto-reload when you change your code. Exit and restart to pick up changes.