Go中应用程序上下文中的REPL控制台

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?

You could try go-pry: https://github.com/d4l3k/go-pry

This works much close to the rails console. Just import "github.com/d4l3k/go-pry/pry" in your file and add pry.Pry() where you want to start your session. After that you just call go-pry main.go instead of go main.go.

But there is not a standard solution, as far as I can tell.