dongxian3852 2014-09-11 13:20
浏览 35
已采纳

我可以在共享的Web服务器上使用go生成HTML吗?

Normally I use C# for everything, I can create a desktop application with C# and also place a lot of the same c# code in a dll on my shared hosted web server. This saves me a lot of coding time.

Is there any way to this with go? e.g. place some kind of go dll on my hosted web server to generate HTML.

I am aware that go doesn't do dll's, I am also aware that creating a web server with go to listen to port 80 is straight forward. But this is not a solution for a shared web server.

This seems like a brilliant use for go and it surprises me that this might not be possible.

I should mention, it would be nice if the go code didn't have to restart with every http request.

This is how I do it with C#: On the web server I add an aspx page like this:

<%@ Page Language="C#" %>
<%@ Register TagPrefix="MyDLL" Namespace="MyDLL" Assembly="MyDLL"%>
<MyDLL:Web Runat="Server"/>

It simply loads the C# dll which generates HTML based on the http request.

  • 写回答

1条回答 默认 最新

  • douzhicong5965 2014-09-11 13:52
    关注

    First you have to setup IIS to use fastcgi (instructions) then you can simply build a go web app like you normally would but instead of using http.ListenAndServe you use fcgi.Serve

    Example:

    func hello(w http.ResponseWriter, r *http.Request) {
        io.WriteString(w, "Hello, world of FCGI!")
    }
    
    func main() {
        http.HandleFunc("/hello/", hello)
    
        if err := fcgi.Serve(nil, nil); err != nil {
            log.Fatal("fcgi.Serve: ", err)
        }
    }
    

    But keep in mind that there can be multiple instances of the programming running / destroyed all the time, so any temp data (in-memory sessions, etc) should be stored on memcache or temp files on disk or a database.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)