我尝试在raspberry pi上运行一个Go get服务器(使用1.10.1),我有一个go get服务器实现了类似(StatPiPrivider.go):
package main
import (
"net/http"
)
func main() {
http.Handle("/", http.FileServer(http.Dir("./static/templates")))
http.ListenAndServe(":3000", nil)
}静态文件夹与StatPiProvider.go文件位于同一个文件夹中。
在这个文件夹中,静态/模板是4个html文件,包括一个index.html
每次我重新启动服务器时,我都会得到一个未找到的响应404页。即使我试图获得另一个html文件,我也会得到相同的响应。
是我的实现出了问题还是我的覆盆子错了。
我运行以下代码:去运行StatPiProvider/StatPiProvider.go
发布于 2018-06-13 22:55:33
请注意,go run不会更改工作目录。因此,您在应用程序中使用的任何相对路径,都将被解析为工作目录,即运行go run的文件夹。
由于static文件夹位于StatPiProvider.go文件的旁边,并且使用路径./static/templates,所以在运行go run时,它们包含的文件夹必须是工作目录。
因此,首先更改dir,使StatPiProvider.go位于工作目录中,然后启动.go文件,如下所示:
cd StatPiProvider
go run StatPiProvider.gohttps://stackoverflow.com/questions/50847302
复制相似问题