Http golang静态服务器始终返回404页未找到

Http golang静态服务器始终返回404页未找到,http,go,webserver,raspberry-pi3,Http,Go,Webserver,Raspberry Pi3,我尝试让Go Web服务器在raspberry pi上运行(使用1.10.1) 我有一个go Web服务器,它的实现类似于(StatPiPrivider.go): 静态文件夹与StatPiProvider.go文件位于同一文件夹中 文件夹static/templates中有4个html文件,包括一个index.html 每次我重新使用服务器时,都会收到一个404页面未找到的响应。即使我尝试获取其他html文件,我也会得到相同的响应 这是我的实现有问题还是我的raspberry有问题 我使用以下命

我尝试让Go Web服务器在raspberry pi上运行(使用1.10.1) 我有一个go Web服务器,它的实现类似于(StatPiPrivider.go):

静态文件夹与StatPiProvider.go文件位于同一文件夹中

文件夹static/templates中有4个html文件,包括一个index.html

每次我重新使用服务器时,都会收到一个404页面未找到的响应。即使我尝试获取其他html文件,我也会得到相同的响应

这是我的实现有问题还是我的raspberry有问题


我使用以下命令运行代码:go run StatPiProvider/StatPiProvider.go

注意,
go run
不会更改工作目录。因此,您在应用程序中使用的任何相对路径,都将解析为工作目录,即运行
go-run
的文件夹

由于
static
文件夹位于
StatPiProvider.go
文件旁边,并且您使用路径
/static/templates
,因此运行
go-run
时,它们包含的文件夹必须是工作目录

因此,首先更改dir,使
StatPiProvider.go
位于工作目录中,然后按如下方式启动
.go
文件:

cd StatPiProvider
go run StatPiProvider.go

当您使用
/static/templates
时,它是当前工作目录的相对路径,取决于进程启动的位置,可能不是您认为的位置。。。使用绝对路径,看看是否有效。
go run
将在tmp文件夹中运行。你应该使用
go-build&./StatPiProvider
cd StatPiProvider
go run StatPiProvider.go