dstjh46606 2018-04-25 00:33
浏览 38

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?

  • 写回答

1条回答 默认 最新

  • duanche4578 2018-04-25 01:20
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序