projecto completo creo, me quedo bonito :3

This commit is contained in:
Daniel Cortés
2019-04-17 12:36:31 -04:00
commit 3c55ad2713
17 changed files with 1356 additions and 0 deletions

20
file_server.go Normal file
View File

@@ -0,0 +1,20 @@
package main
import (
"github.com/go-chi/chi"
"net/http"
)
func fileServer(r chi.Router, path string, root http.FileSystem) {
fs := http.StripPrefix(path, http.FileServer(root))
if path != "/" && path[len(path)-1] != '/' {
r.Get(path, http.RedirectHandler(path+"/", 301).ServeHTTP)
path += "/"
}
path += "*"
r.Get(path, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fs.ServeHTTP(w, r)
}))
}