(root http.FileSystem)
| 39 | } |
| 40 | |
| 41 | func StaticFileServer(root http.FileSystem) http.Handler { |
| 42 | return http.HandlerFunc( |
| 43 | func(w http.ResponseWriter, r *http.Request) { |
| 44 | fileExt := filepath.Ext(r.URL.Path) |
| 45 | |
| 46 | if t, ok := mimeTypes[fileExt]; ok { |
| 47 | w.Header().Set("Content-Type", t) |
| 48 | } |
| 49 | |
| 50 | http.FileServer(root).ServeHTTP(w, r) |
| 51 | }, |
| 52 | ) |
| 53 | } |