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 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出