-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathassets.go
More file actions
44 lines (34 loc) · 1.03 KB
/
assets.go
File metadata and controls
44 lines (34 loc) · 1.03 KB
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
package assets
import (
"embed"
iofs "io/fs"
)
const (
// PlaceholderFileName is the name of the file that is used to populate the directory structure of the embedded assets.
PlaceholderFileName = "placeholder"
)
//go:embed contents/*
var fs embed.FS
type AssetsFS struct {
fs embed.FS
}
func NewAssetsFS() *AssetsFS {
return &AssetsFS{fs: fs}
}
func (a *AssetsFS) ReadDir(name string) ([]iofs.DirEntry, error) {
return a.fs.ReadDir("contents/" + name)
}
func (a *AssetsFS) ReadFile(filename string) ([]byte, error) {
return a.fs.ReadFile("contents/" + filename)
}
// ReadFile reads and returns bytes from the given file in this package's embedded assets.
// Filenames should use forward slashes, not `filepath.Join()`, because go:embed requires '/'.
func ReadFile(filename string) ([]byte, error) {
return fs.ReadFile("contents/" + filename)
}
func OpenFile(filename string) (iofs.File, error) {
return fs.Open("contents/" + filename)
}
func ReadDir(dirname string) ([]iofs.DirEntry, error) {
return fs.ReadDir("contents/" + dirname)
}