我正在尝试学习有关 golang 的在线视频课程,但在提供静态 html 文件时出现错误。package mainimport ( "io/ioutil" "net/http")func main() { http.Handle("/", new(MyHandler)) http.ListenAndServe(":8000", nil)}type MyHandler struct { http.Handler}func (this *MyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { path := "public/" + req.URL.Path data, err := ioutil.ReadFile(string(path)) if err == nil { w.Write(data) } else { w.WriteHeader(404) w.Write([]byte("404 - " + http.StatusText(404))) }}我的文件夹结构 是这样的。
- 2 回答
- 0 关注
- 209 浏览
添加回答
举报
0/150
提交
取消
