aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler/static/handler.go
blob: a8b458324580082c2424b21a65d92c2849e6a836 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package static

import (
	"io/fs"
	"net/http"

	"git.gabrielgio.me/cerrado/static"
)

func ServeStaticHandler() (func(w http.ResponseWriter, r *http.Request), error) {
	staticFs, err := fs.Sub(static.Static, ".")
	if err != nil {
		return nil, err
	}

	return func(w http.ResponseWriter, r *http.Request) {
		f := r.PathValue("file")

		http.ServeFileFS(w, r, staticFs, f)
	}, nil
}