~~~
github.com/gorilla/mux
我吧官方httpfunc的读取JS CSS资源都是可以用的, 存放路径 根目录 /static/js/xxx.js
fileHandler4 := http.StripPrefix("/static/js/", http.FileServer(http.Dir("static/js/"))) //(可用)
fileHandler4.ServeHTTP(w, r)
但是发现mux上不兼容了, 这样的方法无法加载JS文件了
~~~
```
func main() {
var dir="static"
r := mux.NewRouter()
// This will serve files under http://localhost:8000/static/<filename>
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(dir))))
srv := &http.Server{
Handler: r,
Addr: "127.0.0.1:8000",
}
log.Fatal(srv.ListenAndServe())
}
```
http://localhost:8000/static/js/jquery.js
#1