小编jas*_*son的帖子

使用Gorilla工具包为根URL提供静态内容

我试图使用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内容成功传递时,所有jscssURL都返回404.

如何让程序从static子目录中提供文件?

web-applications go mux

55
推荐指数
4
解决办法
3万
查看次数

如何在Spacemacs中折叠Clojure文档字符串

我正在使用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)

这意味着折叠逻辑不需要理解"文档字符串"是什么,而只是折叠选定的行.

clojure code-folding spacemacs

5
推荐指数
1
解决办法
184
查看次数

标签 统计

clojure ×1

code-folding ×1

go ×1

mux ×1

spacemacs ×1

web-applications ×1