dongpang2483 2012-10-19 14:45
浏览 67
已采纳

通过“即时编译”从源代码在Apache下运行.go文件

I'm able to run a Go application as a website with Apache using the following code.

hello.go:

package main

import (
    "os"
)

func main() {
    os.Stdout.WriteString("Content-Type: text/html; charset=UTF-8

")
    os.Stdout.WriteString("Hello!
")
}

.htaccess:

AddHandler cgi-script .exe

I compile the app using go build hello.go and going to http://localhost/hello.exe works as expected.

But now I have to recompile after every change I make in the sourcecode.

Is it somehow possible to tell Apache to run hello.go (Apache should run go run hello.go) when visiting http://localhost/hello.go?

By the way, this is only to speed development, not for production!

  • 写回答

3条回答 默认 最新

  • douyi4991 2012-10-19 17:51
    关注

    An easy solution would be to use a tool which re-compiles your code on changes to the source files. For example GoWatch.

    Or try it yourself by using fsnotify as Erik already stated. Example: Simple Compile Daemon.

    You could also invoke go run in your CGI script.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置