func main() {
mux := http.NewServeMux()
staticHandler := http.FileServer(http.Dir("./templates"))
mux.Handle("/", http.StripPrefix("/", staticHandler))
log.Fatal(http.ListenAndServe(":8080", mux))
}
I want to load a html file which is in 'templates' directory. if there are more than one files in 'templates', how can I select certain file to load?
You can use
http.ServeFile()to build your own file server.See sketch below.
Then you can intercept the served files within your custom
fileHandler.ServeHTTP().