【发布时间】:2014-07-26 19:37:53
【问题描述】:
您好,我正在尝试通过 martini 框架访问和显示静态 index.html 页面。但我总是收到 404 not found 错误。 .html 文件位于 public/index.html 中,其中 /public 目录位于我的 go/src/github.com/user/ 目录中。 我能够显示Hello World!通过代码通过马提尼 -
package main
// loading in the Martini package
import "github.com/codegangsta/martini"
func main() {
// if you are new to Go the := is a short variable declaration
m := martini.Classic()
// the func() call is creating an anonymous function that retuns a stringa
m.Get("/", func() string {
return "Hello World !!"
})
m.Run()
}
所以我确信马提尼酒的配置是正确的。但是当我尝试通过 -
访问静态网页时package main
import (
"github.com/codegangsta/martini"
//"log"
//"net/http"
)
func main() {
m := martini.Classic()
m.Run()
}
我刚刚在 localhot:3000 上得到 404。 任何帮助我如何访问 html 文件?
PS - 我正在尝试做类似这里提到的事情 - https://gophercasts.io/lessons/3-martini-and-markdown
编辑 - 使用m.Use(martini.Static("C:/Users/shrinr/go_projects/go/bin/public"))
也没有帮助,我的 $GOPATH 是 C:/Users/shrinr/go_projects/go。
【问题讨论】:
-
使用 golang.org/pkg/os/#Getwd 并打印返回的值 (log.Println)。我们可以安全地假设您也没有使用
go run吗? -
是的,我正在使用
go run main.go命令来启动/部署 .go 文件。