aboutsummaryrefslogtreecommitdiff
path: root/pkg/ext/fileserver.go
blob: fdea08eb941ad2e92b15c9646aa4c4455c47d6a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package ext

import (
	"io/fs"

	"github.com/valyala/fasthttp"
)

type FileSystem interface {
	Open(name string) (fs.File, error)
}

func FileServer(rootFS FileSystem, rootPath string) fasthttp.RequestHandler {
	return func(r *fasthttp.RequestCtx) {
		path := r.UserValue("filepath").(string)
		r.SendFile(rootPath + path)
	}
}