The following code serves the files inside ./data directory on localhost:8080/:
log.Fatal(http.ListenAndServe(":8080", http.FileServer(http.Dir("./data"))))
The following code does the same:
http.Handle("/", http.FileServer(http.Dir("./data")))
log.Fatal(http.ListenAndServe(":8080", nil))
http.Handle("/h/", http.StripPrefix("/h/", http.FileServer(http.Dir("./data"))))
log.Fatal(http.ListenAndServe(":8080", nil))
My first intuition is to use the following code to serve files on localhost:8080/h. It does not work. But no errors report. What does the following code do?
http.Handle("/h", http.FileServer(http.Dir("./data")))
log.Fatal(http.ListenAndServe(":8080", nil))