<p>Let's say I'm buidling a really simple web server in Go. A minimal example would be:</p>
<pre><code>package main
import (
"fmt"
"html"
"log"
"net/http"
)
func main() {
http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request){
fmt.Fprintf(w, "Hello")
})
log.Fatal(http.ListenAndServe(":8080", 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'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's running as a daemon?</p></li>
</ol>
<p>Thanks!</p>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传