Add wrapper for embed.FS to "fix" it including the full filepath for included files
This commit is contained in:
parent
a969a91746
commit
70f6d19476
1 changed files with 23 additions and 0 deletions
23
embedFsWrapper/wrapper.go
Normal file
23
embedFsWrapper/wrapper.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package embedFsWrapper
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
)
|
||||
|
||||
// Fix for go:embed file systems including the full path of the embedded files
|
||||
// Adds a given string to the front of all requests
|
||||
type FSWrapper struct {
|
||||
wrapped fs.FS
|
||||
toAdd string
|
||||
}
|
||||
|
||||
func NewFSWrapper(wraps fs.FS, appends string) *FSWrapper {
|
||||
return &FSWrapper{
|
||||
wrapped: wraps,
|
||||
toAdd: appends,
|
||||
}
|
||||
}
|
||||
|
||||
func (fs *FSWrapper) Open(name string) (fs.File, error) {
|
||||
return fs.wrapped.Open(fs.toAdd + name)
|
||||
}
|
Loading…
Reference in a new issue