From 056509df907cd1ed679428f5438fbc3707f9cf6c Mon Sep 17 00:00:00 2001 From: Kyle Larose Date: Mon, 15 Aug 2022 14:40:38 -0400 Subject: [PATCH] abstract asset storage The license for open-web-start is BSD 3-clause. The third clause essentially prohibits non-copyright-holders from using the project 'trademarks'. While it calls out only the name of the project/copyright holders, for good measure I don't want to use any of the assets if I package this in another binary. This change abstracts the GUI assets so the packager is responsible for provisioning them. This isn't the *best* interface, since the set of assets is not encoded in the interface, meaning a new version could break compatibility without the compiler catching it. But, it works well enough. We could always extend the interface to have explicit getters in the future if it proves problematic. --- bootstrap/assets.go | 15 +++++++++++++++ {gui => bootstrap}/assets/Icon64.png | Bin {gui => bootstrap}/bindata.go | 2 +- gui/.gitignore | 1 - gui/assets.go | 22 ++++++++++++++++++++++ gui/gui.go | 1 - 6 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 bootstrap/assets.go rename {gui => bootstrap}/assets/Icon64.png (100%) rename {gui => bootstrap}/bindata.go (99%) delete mode 100644 gui/.gitignore create mode 100644 gui/assets.go diff --git a/bootstrap/assets.go b/bootstrap/assets.go new file mode 100644 index 0000000..7e12a54 --- /dev/null +++ b/bootstrap/assets.go @@ -0,0 +1,15 @@ +package bootstrap + +import "github.com/rocketsoftware/open-web-launch/gui" + +//go:generate go-bindata-assetfs -pkg bootstrap assets/... +type assets struct { +} + +func (*assets) Get(name string) ([]byte, error) { + return Asset(name) +} + +func init() { + gui.Assets = &assets{} +} diff --git a/gui/assets/Icon64.png b/bootstrap/assets/Icon64.png similarity index 100% rename from gui/assets/Icon64.png rename to bootstrap/assets/Icon64.png diff --git a/gui/bindata.go b/bootstrap/bindata.go similarity index 99% rename from gui/bindata.go rename to bootstrap/bindata.go index a3f88ec..38bba6c 100644 --- a/gui/bindata.go +++ b/bootstrap/bindata.go @@ -6,7 +6,7 @@ // assets/main.js // DO NOT EDIT! -package gui +package bootstrap import ( "github.com/elazarl/go-bindata-assetfs" diff --git a/gui/.gitignore b/gui/.gitignore deleted file mode 100644 index 459d0de..0000000 --- a/gui/.gitignore +++ /dev/null @@ -1 +0,0 @@ -bindata.go \ No newline at end of file diff --git a/gui/assets.go b/gui/assets.go new file mode 100644 index 0000000..805a680 --- /dev/null +++ b/gui/assets.go @@ -0,0 +1,22 @@ +package gui + +import "errors" + +// AssetGetter provide an interface to retrieve binary asssets packaged with the binary. +type AssetGetter interface { + // Get the asset by name. Returns an error if it does not exist, or if it otherwise + // runs into a problem retrieving it. + Get(name string) ([]byte, error) +} + +// Assets holds the AssetFetcher which can retrieve assets for the binary +var Assets AssetGetter + +// Asset retrieves an asset by name from the provisioned AssetGetter. +func Asset(name string) ([]byte, error) { + if Assets == nil { + return nil, errors.New("no assets provided") + } + + return Assets.Get(name) +} diff --git a/gui/gui.go b/gui/gui.go index 1243ca4..f3d597d 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -1,6 +1,5 @@ package gui -//go:generate go-bindata-assetfs -pkg gui assets/... import ( "bytes"