dongpigui8898 2014-11-28 17:02
浏览 60

通过处理模板来改变语言的奇怪行为

gotemplates
Hello!

I'm learning Go language now and trying to port some simple WEB code (Laravel 4). Everything was well, until I tried to reproduce Blade templates into text templates. I found that Go can load my CSS and JavaScript files only from the catalog with a name "bootstrap" only.

Here is my catalog tree which I tried to use:

start-catalog
  bootstrap (link to bootstrap-3.3.1)
      bootstrap-3.3.1
    css
      bootstrap.min.css
    js
      bootstrap.min.js
  jquery
    jquery (link to jquery-2.1.1.min.js) 
    jsquery-2.1.1.min.js
  go_prg.go

Here are my templates:

base_js.tmpl

{{define "base_js"}}
      {{template "login_1"}}

      <script src = "/bootstrap/js/jquery"></script>
      <script src = "/bootstrap/js/bootstrap.min.js"></script>
{{end}}

base_header.tmpl

{{define "base_header"}} <head> <title>PAGE TITLE</title> <meta name = "viewport" content = "width=device-width, initial-scale=1.0"> <meta charset="utf-8"> <link href = "/bootstrap/css/bootstrap.min.css" rel = "stylesheet"> </head> {{end}}

If the catalog name differs from "bootstrap" Go language or Firefox can't load files from the templates above: bootstrap.min.css, bootstrap.min.js, jquery.
If I use not the link but the catalog name directly "bootstrap-3.3.1" than Go or Firefox can't load.
If all required files are moved under "bootstrap" I'm getting the results I expected (exactly the same as in Laravel 4).

To launch go language code the command go run go_prg.go was used.
Environment: Ubuntu 14.04, go-1.3.3, Firefox 31.

Who's wrong: Go language, Firefox or me?

Any help will be highly appreciated!

  • 写回答

1条回答 默认 最新

  • drfu80954 2014-12-05 19:33
    关注

    The problem described was caused by

    http.Handle("/bootstrap/", http.StripPrefix("/bootstrap/", http.FileServer(http.Dir("bootstrap"))))
    

    before any template was handled. It allowed access files under the directory 'bootstrap' only.

    The problem was fixed by changing to http.Handle( , http.StripPrefix(, http.FileServer(http.Dir(".")))) and adding to pathes for CSS and JavaScript files. Like so

    /bootstrap/js/jquery">.

    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)