-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassets.go
More file actions
32 lines (26 loc) · 808 Bytes
/
assets.go
File metadata and controls
32 lines (26 loc) · 808 Bytes
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
package PluginLib
import (
"embed"
"io/fs"
)
// AssetManager provides access to embedded assets.
type AssetManager struct {
fs fs.FS
}
// RegisterAssets registers an embedded filesystem for the plugin.
func RegisterAssets(embeddedFS *embed.FS) *AssetManager {
return &AssetManager{fs: embeddedFS}
}
// GetAsset reads an embedded asset as a byte slice.
func (am *AssetManager) GetAsset(path string) ([]byte, error) {
return fs.ReadFile(am.fs, path)
}
// GetAssetString reads an embedded asset as a string.
func (am *AssetManager) GetAssetString(path string) (string, error) {
data, err := am.GetAsset(path)
return string(data), err
}
// OpenAsset returns an fs.File for streaming or advanced use cases.
func (am *AssetManager) OpenAsset(path string) (fs.File, error) {
return am.fs.Open(path)
}