From 5a4dcd52b059eb9233235f89bcc49b53c5f81270 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sun, 18 Jul 2021 22:47:34 +0200 Subject: [PATCH] Added embedres. - Exposes embed.FS (native) as a ui.Resources. --- addons/embedres/embedres.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 addons/embedres/embedres.go diff --git a/addons/embedres/embedres.go b/addons/embedres/embedres.go new file mode 100644 index 0000000..a5156fe --- /dev/null +++ b/addons/embedres/embedres.go @@ -0,0 +1,24 @@ +package embedres + +import ( + "embed" + "io" + + "opslag.de/schobers/zntg/ui" +) + +var _ ui.Resources = &resources{} + +type resources struct { + fs embed.FS +} + +func New(fs embed.FS) ui.Resources { + return &resources{fs} +} + +func (r resources) Destroy() error { return nil } + +func (r resources) OpenResource(name string) (io.ReadCloser, error) { + return r.fs.Open(name) +}