Go:使用gorilla mux提供CSS文件

use*_*985 1 go gorilla

我有这个目录结构,我正在使用Gorilla mux:

目录结构

twitter
    layout
        stylesheets
            log.css
        log.html
    twitter.go
Run Code Online (Sandbox Code Playgroud)

按照这里的建议:http://www.shakedos.com/2014/Feb/08/serving-static-files-with-go.html我这样做了:

var router = mux.NewRouter()

func ServeStatic(router *mux.Router, staticDirectory string) {
    staticPaths := map[string]string{
        "styles": staticDirectory + "stylesheets",
        }
    for pathName, pathValue := range staticPaths {
        pathPrefix := "/" + pathName + "/"
        router.PathPrefix(pathPrefix).Handler(http.StripPrefix(pathPrefix,
        http.FileServer(http.Dir(pathValue))))
    }
}

var staticDirectory = "/layout/"

func main() {
    (//other code)
    ServeStatic(router, staticDirectory)
}
Run Code Online (Sandbox Code Playgroud)

我还是无法链接CSS文件.我究竟做错了什么?

use*_*985 6

解决.

我在func main()中添加了这个

router.PathPrefix("/").Handler(http.FileServer(http.Dir("./layout/")))
Run Code Online (Sandbox Code Playgroud)