func main() { fs := FileServerWith404(http.Dir("my_static_files")) http.Handle("/", http.StripPrefix("/", fs)) http.ListenAndServe(":3000") }
func FileServerWith404(root http.FileSystem) http.Handler { fs := http.FileServer(root) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { f, err := root.Open(r.URL.Path) if err != nil && os.IsNotExist(err) { // Make sure you actually have an HTML file at my_static_files/404/index.html r.URL.Path = "/404" } if err == nil { f.Close() } fs.ServeHTTP(w, r) }) } On Friday, January 3, 2014 at 7:06:09 AM UTC-5 dan....@gmail.com wrote: No, I after looking through the FileServer code I found my problem, I'm on windows, and I was trying to use a the windows \ in the path, not the unix / in the path, but there was a comment in the FileServer code that stats the path should always be / not matter what OS. On Friday, January 3, 2014 2:42:43 AM UTC-5, DisposaBoy wrote:A wild guess: you shouldn't be stripping the trailing slash -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b9ce1270-a43d-4d46-811b-de37e6b27031n%40googlegroups.com.