From 70f6d19476362f513512f0a59df41c4c1c2ea7b4 Mon Sep 17 00:00:00 2001 From: mStar aka a person <12024604-mstarongitlab@users.noreply.gitlab.com> Date: Wed, 21 Feb 2024 14:12:50 +0100 Subject: [PATCH] Add wrapper for embed.FS to "fix" it including the full filepath for included files --- embedFsWrapper/wrapper.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 embedFsWrapper/wrapper.go diff --git a/embedFsWrapper/wrapper.go b/embedFsWrapper/wrapper.go new file mode 100644 index 0000000..e266f91 --- /dev/null +++ b/embedFsWrapper/wrapper.go @@ -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) +}