无法通过马提尼框架访问静态网页index.html

时间:2014-07-26 19:37:53

标签: html go martini

您好我正在尝试通过马提尼框架访问并显示静态index.html页面。但我总是得到404找不到错误。 .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上得到404:3000。 任何帮助如何访问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。

1 个答案:

答案 0 :(得分:0)

假设您使用Go的标准程序(在$GOPATH中)编译程序,问题是您的二进制文件与public/文件夹不在同一目录中。你应该把它放在$GOPATH/bin文件夹中(二进制文件应该放在哪里)。