blob: 7b2704bb2c1ca099afab0824c68199649ae53814 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)
}
}
|