-
Notifications
You must be signed in to change notification settings - Fork 1
/
genfs.go
40 lines (31 loc) · 801 Bytes
/
genfs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package genfs
import (
"io/fs"
"strings"
"github.com/matthewmueller/genfs/internal/cache"
"github.com/matthewmueller/genfs/internal/tree"
"github.com/matthewmueller/virt"
)
type FS fs.FS
type FileGenerator interface {
GenerateFile(fsys FS, file *File) error
}
type DirGenerator interface {
GenerateDir(fsys FS, dir *Dir) error
}
type GeneratorFunc func(cache cache.Interface, target string) (*virt.File, error)
func (fn GeneratorFunc) Generate(cache cache.Interface, target string) (*virt.File, error) {
return fn(cache, target)
}
func New(fsys fs.FS) *FileSystem {
return &FileSystem{fsys, tree.New()}
}
func relativePath(base, target string) string {
rel := strings.TrimPrefix(target, base)
if rel == "" {
return "."
} else if rel[0] == '/' {
rel = rel[1:]
}
return rel
}