25 lines
580 B
Go
25 lines
580 B
Go
// Package embedFsWrapper contains a wrapper around [io/fs.FS] for working
|
|
// around a limitation of the [embed] package
|
|
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)
|
|
}
|