From 85e7eaa3a1c9024c02cc9a63744cdfb144cc3737 Mon Sep 17 00:00:00 2001 From: Max Resnick Date: Sat, 23 May 2020 07:56:12 -0700 Subject: adds tmpl, css, and fileserver --- internal/fs/fs.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 internal/fs/fs.go (limited to 'internal/fs/fs.go') diff --git a/internal/fs/fs.go b/internal/fs/fs.go new file mode 100644 index 0000000..7b2704b --- /dev/null +++ b/internal/fs/fs.go @@ -0,0 +1,18 @@ +package fs + +import ( + "net/http" + "strings" + + "github.com/go-chi/chi" +) + +func NewHandler(path string) http.HandlerFunc { + filesDir := http.Dir(path) + return func(w http.ResponseWriter, r *http.Request) { + rctx := chi.RouteContext(r.Context()) + pathPrefix := strings.TrimSuffix(rctx.RoutePattern(), "/*") + fs := http.StripPrefix(pathPrefix, http.FileServer(filesDir)) + fs.ServeHTTP(w, r) + } +} -- cgit v1.2.3