服务JS文件的错误

时间:2015-04-10 09:55:25

标签: go

我有这个目录结构

src/
  github.com/
    john/
      site/
        main.go
        templates/
          index.html
        static/
          js/
            site.js
          css/

在我的main.go中:

func main() {
  http.Handle("/templates/", http.StripPrefix("/templates/", http.FileServer(http.Dir(filepath.Join(cwd, "/github.com/john/site/templates/"))))
  http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(filepath.Join(cwd, "/github.com/john/site/static/"))))

在index.html中

<script src="/static/js/site.js"></script>

HTML正确加载。但是,没有找到这样的js文件。为什么会这样?

我在src目录中运行go install。此外,当我尝试访问localhost:3000 / templates / index.html时,也找不到该文件。

1 个答案:

答案 0 :(得分:0)

js文件夹不在静态下。它应该像

static/
      js/
        site.js
相关问题