diff options
| author | Max Resnick <max@ofmax.li> | 2020-05-23 07:56:12 -0700 |
|---|---|---|
| committer | Max Resnick <max@ofmax.li> | 2020-06-22 22:37:17 -0700 |
| commit | 85e7eaa3a1c9024c02cc9a63744cdfb144cc3737 (patch) | |
| tree | a44855abcf5424126c54ee636463dc866e558561 /internal/fs | |
| parent | 4e77ad5762539d8f9edf40d2668a998c38e834d3 (diff) | |
| download | iserv-85e7eaa3a1c9024c02cc9a63744cdfb144cc3737.tar.gz | |
adds tmpl, css, and fileserver
Diffstat (limited to '')
| -rw-r--r-- | internal/fs/fs.go | 18 |
1 files changed, 18 insertions, 0 deletions
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) + } +} |