Add wrapper for embed.FS to "fix" it including the full filepath for included files

This commit is contained in:
mStar aka a person 2024-02-21 14:12:50 +01:00
parent a969a91746
commit 70f6d19476

23
embedFsWrapper/wrapper.go Normal file
View 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)
}