-
Notifications
You must be signed in to change notification settings - Fork 6
/
embeddedFileSystem.go
52 lines (42 loc) · 1.32 KB
/
embeddedFileSystem.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
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package embedded
import (
"embed"
"io/fs"
galasaErrors "github.com/galasa-dev/cli/pkg/errors"
)
type ReadOnlyFileSystem interface {
ReadFile(filePath string) ([]byte, error)
ReadDir(directoryPath string) ([]fs.DirEntry, error)
}
type EmbeddedFileSystem struct {
embeddedFileSystem embed.FS
}
func NewReadOnlyFileSystem() ReadOnlyFileSystem {
result := EmbeddedFileSystem{
embeddedFileSystem: embeddedFileSystem,
}
return &result
}
//------------------------------------------------------------------------------------
// Interface methods...
//------------------------------------------------------------------------------------
// The only thing which this class actually supports.
func (fs *EmbeddedFileSystem) ReadFile(filePath string) ([]byte, error) {
bytes, err := fs.embeddedFileSystem.ReadFile(filePath)
if err != nil {
galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_EMBEDDED_FS_READ_FAILED, err.Error())
}
return bytes, err
}
func (fs *EmbeddedFileSystem) ReadDir(directoryPath string) ([]fs.DirEntry, error) {
dirEntries, err := fs.embeddedFileSystem.ReadDir(directoryPath)
if err != nil {
galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_EMBEDDED_FS_READ_FAILED, err.Error())
}
return dirEntries, err
}