sub
stripPrefix调用中的路径)
sub.Handle("/static", http.StripPrefix("/sub/static", http.FileServer(http.Dir("./"))))
package main
import (
"net/http"
"github.com/gorilla/mux"
)
func index(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Index"))
}
func main() {
r := mux.NewRouter()
r.Handle("/static", http.StripPrefix("/static", http.FileServer(http.Dir("./"))))
r.HandleFunc("/", index)
sub := r.PathPrefix("/sub").Subrouter()
sub.Handle("/static", http.StripPrefix("/sub/static", http.FileServer(http.Dir("./"))))
sub.HandleFunc("/", index)
http.ListenAndServe(":8080", r)
}