Is there a way to access an interactive REPL console in the context of an application, in Go?
For reference, I'm thinking about the functionality of Ruby's irb or pry (and, by extension, the Ruby On Rails console that builds on them), the Node.js REPL, the Scala REPL (and Play console) or Elixir's IEx. All of these are development (or production!) tools to open a REPL in the context of an application. For example, they allow to access an application's classes, objects and constants, and by extension to interact with the application's resources (e.g. a database).
There are some Go REPLs out there, like gore, but it's not clear how to plug them into an application.
I suppose it would be possible to start a gore
session and then import all packages, but what about the initializations that happen in the main
?
My instinct tells me that there should be a way to provide an alternative "REPL-only" main
to compile a different binary that starts the application as a REPL -- rather than, say, an HTTP server.
Is there any established way to do so? Or a reference implementation?