0
以下代碼中的任何錯誤?多個目錄服務不能從下面的代碼中運行。當我訪問localhost:9090/ide時,服務器將返回404錯誤。多個Dir服務不起作用
package main
import (
"log"
"net/http"
)
func serveIDE(w http.ResponseWriter, r *http.Request) {
http.FileServer(http.Dir("/home/user/ide")).ServeHTTP(w, r)
}
func serveConsole(w http.ResponseWriter, r *http.Request) {
http.FileServer(http.Dir("/home/user/console")).ServeHTTP(w, r)
}
func main() {
http.HandleFunc("/ide", serveIDE)
http.HandleFunc("/console", serveConsole)
err := http.ListenAndServe(":9090", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
當我改變這樣的代碼,
http.HandleFunc("/", serveIDE)
它將工作如我所料。