一个读取Go文件并执行的应用程序

huangapple go评论71阅读模式
英文:

An application that read go files and execute it

问题

我正在开发我的 Web 应用程序,并使用 Revel 框架。要执行 Revel 应用程序,我运行以下代码:

revel run myapp

现在,我真的很想知道 Revel 是如何工作的。我的问题是,Revel 框架如何使用我为应用程序编写的多个 Go 文件来执行 myapp?Revel 是一个虚拟机吗?

我该如何使用 Go 编写应用程序、读取 Go 文件并执行它们?

英文:

I am working on my webapplication and using the revel framework. To execute an revel application, I run
the following code

revel run myapp

Now, I am really wonder how revel approximately works. My question is, how do revel framework execute myapp with many go files, that I wrote for the application? Is revel
a virtual machine?

How can I write an application in Go and read Go files and execute it?

答案1

得分: 3

不,revel不是一个虚拟机。当你修改源代码时,revel会重新编译它。

这在http://revel.github.io/的功能描述中有说明:

热代码重新加载
编辑、保存和刷新。Revel会为您编译代码和模板,所以您不会错过任何东西。代码无法编译?它会给出有用的描述。运行时代码恐慌?Revel会帮助您解决。

Go源代码编译非常快,因此这变得可能。

英文:

No, revel is not a virtual machine. Revel recompile your source code when you modify it.

That is described in features on http://revel.github.io/
>Hot Code Reload
>Edit, save, and refresh. Revel compiles your code and templates for you, so you don't miss a beat. Code doesn't compile? It gives you a helpful description. Run-time code panic? Revel has you covered.

Go sources compiles very fast, so it becomes possible

答案2

得分: 2

Revel是一个预处理器而不是一个框架。它将Go的工作抽象化,并引入了自己的代码结构和概念。这在Go社区中通常是不被赞同的,但这不是你问题的主题,所以我也不会将其作为这个答案的内容。

它的工作方式是将你的代码与自己的样板代码结合起来,并将所有内容编译在一起。

我如何在Go中编写一个应用程序并读取Go文件并执行它?

你可以编写一个REPL(Read-Eval-Print Loop),或者像Revel一样,通过使用Go编译器套件来编写一个应用程序,该应用程序将编译其他Go应用程序。


编辑以回答评论中的问题:Revel本身是一个很好的例子。在第73行上,它执行go build命令,并设置输出为binName,它是一个临时文件的路径。

英文:

Revel is a pre-processor rather than a framework. It abstracts Go's workings away and introduces it's own code structure and concepts. This is generally frowned upon in the Go community but that's not the topic of your question and so neither will I make it that of this answer.

The way it does that is by combining your code with boilerplate of its own and compiling everything together.

> How can I write an application in Go and read Go files and execute it?

Either you write a REPL or you do like Revel and just make an application which will compile other Go applications through the use of the Go compiler suite.

<hr>

Edit to answer question in the comments: Revel itself is a pretty good example. here on line 73 it executes go build with some flags and sets the output to binName which is a path to a temporary file.

答案3

得分: 0

Revel不是一个虚拟机,实际上它是一个Go语言的框架。

正如Revel的主页所说:

热代码重新加载

编辑、保存和刷新。Revel会为您编译代码和模板,确保您不会错过任何东西。代码无法编译?它会给出有用的描述。运行时代码恐慌?Revel会帮助您解决问题。
英文:

Revel is not a virtual machine. Infact it's a framework in Go.

As the home page of Revel says:

Hot Code Reload

Edit, save, and refresh. Revel compiles your code and templates for you, so you don&#39;t miss a beat. Code doesn&#39;t compile? It gives you a helpful description. Run-time code panic? Revel has you covered.

huangapple
  • 本文由 发表于 2014年9月10日 15:52:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/25760050.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定