Deploying my first Go web app and had a few questions

polaris · · 34 次点击    
<p>Let&#39;s say I&#39;m buidling a really simple web server in Go. A minimal example would be:</p> <pre><code>package main import ( &#34;fmt&#34; &#34;html&#34; &#34;log&#34; &#34;net/http&#34; ) func main() { http.HandleFunc(&#34;/hello&#34;, func(w http.ResponseWriter, r *http.Request){ fmt.Fprintf(w, &#34;Hello&#34;) }) log.Fatal(http.ListenAndServe(&#34;:8080&#34;, nil)) } </code></pre> <p>Locally I this with <code>go run *.go</code> and I can hit <code>localhost:8080/hello</code> to get a response.</p> <p>I&#39;d like to run this on a server somewhere, such as a VPS (e.g. 123.123.50.50)</p> <ol> <li><p>Should I build/compile this code into an executable and run it? Or is it sufficient to use <code>go run *.go</code> on the remote server as well? If not, how does one build and run the binary?</p></li> <li><p>Once I get it running, would my page automatically be available at <code>http://123.123.50.50:8080/hello</code>? Or do I need to set up something like nginx to route all the incoming requests to my Go process that&#39;s running as a daemon?</p></li> </ol> <p>Thanks!</p>
34 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet