Is the build-in HTTP server necessary for every web app?

blov · · 501 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>So far I know only one way of writing Go applications.</p> <p>Use the, built in HTTP server, listen on a port and serve files.</p> <p>Are there other ways of invoking Go code?</p> <p>Let&#39;s say I have a mainly static website, for the most part I don&#39;t need back-end code. However, I would like to add an email form in the &#39;contact me&#39; page. </p> <p>In PHP I would just add a small <code>.php</code> file that handles the email form.</p> <p>But to achieve the same effect with Go, do I need to wrap the whole website in Go code (HTTP, handlers, email form etc.), or can I add just a small Go binary that only handles the email form and doesn&#39;t do anything else (invoked by Nginx when needed)?</p> <p><strong>Related question:</strong> When using a reverse proxy like Nginx, does one always communicate with Go apps via HTTP or are there other ways of executing the Go code?</p> <hr/>**评论:**<br/><br/>sthussey: <pre><p>You are probably looking for FCGI - <a href="https://golang.org/pkg/net/http/fcgi/" rel="nofollow">https://golang.org/pkg/net/http/fcgi/</a></p></pre>YoungMacBo: <pre><p>Oh dear god:</p> <blockquote> <p>Package fcgi implements the FastCGI protocol. Currently only the responder role is supported. The protocol is defined at <a href="http://www.fastcgi.com/drupal/node/6?q=node/22" rel="nofollow">http://www.fastcgi.com/drupal/node/6?q=node/22</a></p> </blockquote> <p>and of course....</p> <blockquote> <p><strong>Not Found</strong><br/> The requested URL /drupal/node/6 was not found on this server.</p> </blockquote> <p>Drupal, not even once<em>!!</em></p></pre>esantoro: <pre><p>That is not a drupal issue, the whole website is offline.</p> <p><a href="https://github.com/FastCGI-Archives/FastCGI.com" rel="nofollow">https://github.com/FastCGI-Archives/FastCGI.com</a></p> <p>This is a mirror of the website, more or less.</p></pre>nathforge: <pre><p>There&#39;s CGI, which is old-school but only runs your app when needed - NGINX doesn&#39;t support it though.</p> <p>A newer (relatively) alternative is FastCGI which NGINX <em>does</em> support - it behaves similarly to a reverse proxy, in that your Go app stays in memory.</p> <p>Reverse proxy is your best bet, honestly.</p></pre>daniels0xff: <pre><p>And nothing is wrong with that. Reverse proxy is fine.</p></pre>joncalhoun: <pre><p>You could probably also subdomain and adjust your security settings to allow it if you need any specific cookie info. For a mostly static page with simple forms that would be an exceptionally easy setup.</p></pre>CaptaincCodeman: <pre><p>Another approach - look for hosting that allows routing between dynamic / static instance.</p> <p>AppEngine for instance would allow you to set certain paths to be served through their CDN (the static files) and others to hit your app instance for processing by Go code.</p> <p>Your Go app doesn&#39;t need to be concerned serving up static files then. It&#39;s similar to what you could do with Nginx, just built in to the platform.</p></pre>hobbified: <pre><p>Just have your webserver serve the static parts directly, and only forward requests for the dynamic parts to a go app (or more than one of them, if that floats your boat). No need to have everything under one process if you don&#39;t want to, and no need to have go do something your webserver can do better.</p></pre>DanChm: <pre><p>That&#39;s a good tip, I&#39;ll definitely try this.</p></pre>seriouslulz: <pre><p>Just use PHP</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

501 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传