慕桂英3389331
对于一个简单的“一网打尽”,你可以做http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "index.html")})“/”模式匹配所有内容。对于更复杂的模式,您需要使用重写 url 的处理程序包装您的多路复用器。// register your handlers on a new muxmux := http.NewServeMux()mux.HandleFunc("/path", func(w http.ResponseWriter, r *http.Request) { // your handler code})...rewrite := func(path string) string { // your rewrite code, returns the new path}...// rewrite URL.Path in here before calling mux.ServeHTTPhttp.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { r.URL.Path = rewrite(r.URL.Path) mux.ServeHTTP(w,r)})