-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoblin.go
61 lines (49 loc) · 1.4 KB
/
goblin.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Package goblin provides interaction with various types of filesystems, including those
// embedded in the binary.
//
// It's designed to implement the proposed Go standard library filesystem interfaces. Since
// these interfaces do not exist in a stable release yet, they've been included in this package
// for now. Eventually those interfaces will be removed in favor of the stable release. Types
// that are included temporarily are noted in their documentation.
package goblin
import (
"fmt"
"time"
)
// Refer to https://go.googlesource.com/proposal/+/master/design/draft-iofs.md for FS implementation
const (
pathSeparator = "/"
)
// Vault is the interface that provides all the interfaces a Goblin vault must implement.
type Vault interface {
StatFS
ReadDirFS
ReadFileFS
fmt.Stringer
}
// GlobVault is an interface that provides a Vault in addition to a GlobFS.
type GlobVault interface {
Vault
GlobFS
}
// FileOption is a common set of options used when creating or
// managing files.
type FileOption func(*fileOptions)
type fileOptions struct {
ModTime time.Time
}
func newFileOptions(opts ...FileOption) *fileOptions {
fo := &fileOptions{
ModTime: time.Now(),
}
for _, opt := range opts {
opt(fo)
}
return fo
}
// FileModTime specifies the modified time to use for the file.
func FileModTime(modTime time.Time) FileOption {
return func(fOpts *fileOptions) {
fOpts.ModTime = modTime
}
}