我试图使用Gorilla工具包的mux包来路由Go Web服务器中的URL.利用这个问题为导向,我有以下Go代码:
func main() {
r := mux.NewRouter()
r.Handle("/", http.FileServer(http.Dir("./static/")))
r.HandleFunc("/search/{searchTerm}", Search)
r.HandleFunc("/load/{dataId}", Load)
http.Handle("/", r)
http.ListenAndServe(":8100", nil)
}
Run Code Online (Sandbox Code Playgroud)
目录结构是:
...
main.go
static\
| index.html
| js\
| <js files>
| css\
| <css files>
Run Code Online (Sandbox Code Playgroud)
Javascript和CSS文件的引用方式index.html如下:
...
<link rel="stylesheet" href="css/redmond/jquery-ui.min.css"/>
<script src="js/jquery.min.js"></script>
...
Run Code Online (Sandbox Code Playgroud)
当我http://localhost:8100在我的Web浏览器中访问index.html内容成功传递时,所有js和cssURL都返回404.
如何让程序从static子目录中提供文件?
我正在使用Spacemacs在Clojure中编写程序.我希望能够折叠docstrings.我已经尝试选择文档字符串并按下z a,但最终会折叠整个函数体.
具体来说,我希望能够解决这个问题:
(defn flip-and-vectorize
"Returns a vector with the arguments flipped so that
`(flip-and-vectorize 1 2)`
returns the following vector
`[2 1]`"
[a b]
[b a])
Run Code Online (Sandbox Code Playgroud)
变成类似于此的东西
(defn flip-and-vectorize
"..."
[a b]
[b a])
Run Code Online (Sandbox Code Playgroud)
编辑:
即使能够折叠任意线也是可以接受的; 意味着上面函数的折叠版本看起来像这样:
(defn flip-and-vectorize
...
[a b]
[b a])
Run Code Online (Sandbox Code Playgroud)
这意味着折叠逻辑不需要理解"文档字符串"是什么,而只是折叠选定的行.