4
如何使用Go Web服务器提供静态html文件?
如何使用Go Web服务器提供index.html(或其他静态HTML文件)? 我只想要一个基本的静态HTML文件(例如,一篇文章),就可以从Go Web服务器上提供该文件。HTML应该可以在go程序之外进行修改,就像使用HTML模板时一样。 这是我的Web服务器,仅托管硬编码文本(“ Hello world!”)。 package main import ( "fmt" "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello world!") } func main() { http.HandleFunc("/", handler) http.ListenAndServe(":3000", nil) }
89
go