diff --git a/Makefile b/Makefile index ddd4b97cf..e6e8c3425 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,7 @@ clean: rm -f notifiarr notifiarr.*.{macos,freebsd,linux,exe}{,.gz,.zip} notifiarr.1{,.gz} notifiarr.rb rm -f notifiarr{_,-}*.{deb,rpm,txz} v*.tar.gz.sha256 examples/MANUAL .metadata.make rsrc_*.syso rm -f cmd/notifiarr/README{,.html} README{,.html} ./notifiarr_manual.html rsrc.syso Notifiarr.*.app.zip - rm -f notifiarr.service pkg/bindata/bindata.go pack.temp.dmg notifiarr.conf.example + rm -f notifiarr.service pack.temp.dmg notifiarr.conf.example rm -rf package_build_* release Notifiarr.*.app Notifiarr.app rm -f pkg/bindata/docs/api_docs.go @@ -355,12 +355,10 @@ lint: generate GOOS=freebsd golangci-lint --build-tags nodbus run GOOS=windows golangci-lint run -generate: pkg/bindata/bindata.go pkg/bindata/docs/api_docs.go +generate: pkg/bindata/docs/api_docs.go pkg/bindata/docs/api_docs.go: - go generate ./pkg/bindata/docs -pkg/bindata/bindata.go: find pkg -name .DS\* -delete - go generate ./pkg/bindata/ + go generate ./pkg/bindata/docs ################## ##### Docker ##### diff --git a/init/docker/Dockerfile.alpine b/init/docker/Dockerfile.alpine index 1286232a5..d81d5648d 100644 --- a/init/docker/Dockerfile.alpine +++ b/init/docker/Dockerfile.alpine @@ -12,8 +12,7 @@ COPY main.go go.mod go.sum ./ # Cache all the needed tools. RUN go mod download \ - && go run github.com/kevinburke/go-bindata/v4/go-bindata@latest -v \ - && go run github.com/swaggo/swag/cmd/swag@master -v + && go run github.com/swaggo/swag/cmd/swag@latest -v COPY pkg pkg RUN go generate ./... diff --git a/init/docker/Dockerfile.cuda b/init/docker/Dockerfile.cuda index 3d4ee09d1..1d0fb0f8f 100644 --- a/init/docker/Dockerfile.cuda +++ b/init/docker/Dockerfile.cuda @@ -12,8 +12,7 @@ COPY main.go go.mod go.sum ./ # Cache all the needed tools. RUN go mod download \ - && go run github.com/kevinburke/go-bindata/v4/go-bindata@latest -v \ - && go run github.com/swaggo/swag/cmd/swag@master -v + && go run github.com/swaggo/swag/cmd/swag@latest -v COPY pkg pkg RUN go generate ./... diff --git a/init/docker/Dockerfile.scratch b/init/docker/Dockerfile.scratch index 865f01d28..0f3cb8639 100644 --- a/init/docker/Dockerfile.scratch +++ b/init/docker/Dockerfile.scratch @@ -12,8 +12,7 @@ COPY main.go go.mod go.sum ./ # Cache all the needed tools. RUN go mod download \ - && go run github.com/kevinburke/go-bindata/v4/go-bindata@latest -v \ - && go run github.com/swaggo/swag/cmd/swag@master -v + && go run github.com/swaggo/swag/cmd/swag@latest -v # Cache apt installs. RUN apt update \ diff --git a/pkg/bindata/.gitignore b/pkg/bindata/.gitignore index 581f91ba5..fff0ee588 100644 --- a/pkg/bindata/.gitignore +++ b/pkg/bindata/.gitignore @@ -1,2 +1 @@ api_docs.go -bindata.go \ No newline at end of file diff --git a/pkg/bindata/README.md b/pkg/bindata/README.md index e4e945b92..0e485c96a 100644 --- a/pkg/bindata/README.md +++ b/pkg/bindata/README.md @@ -1,13 +1 @@ -The files in this folder are auto generated from the files/ and templates/ folders. - -- To generate the binary base64 data you need to install `go-bindata`: - -```shell -curl --silent --location --output /usr/local/bin/go-bindata https://github.com/kevinburke/go-bindata/releases/download/v3.22.0/go-bindata-linux-amd64 -chmod 755 /usr/local/bin/go-bindata -make generate -``` - -See: https://github.com/kevinburke/go-bindata - -- **Do not put anything except Go HTML template files in the templates/ directory.** \ No newline at end of file +- **Do not put anything except Go HTML template files in the templates/ directory.** diff --git a/pkg/bindata/bindata.go b/pkg/bindata/bindata.go new file mode 100644 index 000000000..1c9e50ea6 --- /dev/null +++ b/pkg/bindata/bindata.go @@ -0,0 +1,13 @@ +// Package bindata provides file system assets to the running binary. +package bindata + +import "embed" + +var ( + //go:embed files + Files embed.FS + //go:embed templates + Templates embed.FS + //go:embed other/fortunes.txt + Fortunes string +) diff --git a/pkg/bindata/docs/generate.go b/pkg/bindata/docs/generate.go index be477b624..fab4d2266 100644 --- a/pkg/bindata/docs/generate.go +++ b/pkg/bindata/docs/generate.go @@ -1,3 +1,3 @@ package docs -//go:generate go run github.com/swaggo/swag/cmd/swag@v1.8.12 i --parseDependency --instanceName api --outputTypes go --parseInternal --dir ../../../ -g main.go --output . +//go:generate go run github.com/swaggo/swag/cmd/swag@latest i --parseDependency --instanceName api --outputTypes go --parseInternal --dir ../../../ -g main.go --output . diff --git a/pkg/bindata/generate.go b/pkg/bindata/generate.go deleted file mode 100644 index bcc54c731..000000000 --- a/pkg/bindata/generate.go +++ /dev/null @@ -1,9 +0,0 @@ -// Package bindata provides the go:generate command to create new base64 binary -// data, as well as the binary data itself, in both formats. That means, you will -// find the _things_ we compress into base64 inside the files/ directory, and you -// will find the base64 files in the bindata.go file. The generate.go file contains -// the command that creates the binary data. -// See: https://github.com/kevinburke/go-bindata or the README.md file. -package bindata - -//go:generate go run github.com/kevinburke/go-bindata/v4/go-bindata@latest -pkg bindata -modtime 1587356420 -o bindata.go files/... templates/... other/... diff --git a/pkg/bindata/tools.go b/pkg/bindata/tools.go index df2dc0655..f6eee02e0 100644 --- a/pkg/bindata/tools.go +++ b/pkg/bindata/tools.go @@ -6,8 +6,6 @@ package bindata import ( // Used to build windows exe metadata. _ "github.com/akavel/rsrc" - // Used to convert static files to internal binary data. - _ "github.com/kevinburke/go-bindata/v4" // Used to create API docs. _ "github.com/swaggo/swag" ) diff --git a/pkg/client/cli.go b/pkg/client/cli.go index 244bc0263..2adca0513 100644 --- a/pkg/client/cli.go +++ b/pkg/client/cli.go @@ -167,7 +167,7 @@ func printCurlReply(resp *http.Response, body []byte) { // Fortune returns a fortune. func Fortune() string { - fortunes := strings.Split(bindata.MustAssetString("other/fortunes.txt"), "\n%\n") + fortunes := strings.Split(bindata.Fortunes, "\n%\n") return fortunes[rand.Intn(len(fortunes))] //nolint:gosec } diff --git a/pkg/client/handlers.go b/pkg/client/handlers.go index 99e641bc0..145a43166 100644 --- a/pkg/client/handlers.go +++ b/pkg/client/handlers.go @@ -152,7 +152,7 @@ func (c *Client) slash(response http.ResponseWriter, request *http.Request) { } func (c *Client) favIcon(w http.ResponseWriter, r *http.Request) { //nolint:varnamelen - ico, err := bindata.Asset("files/images/favicon.ico") + ico, err := bindata.Files.ReadFile("files/images/favicon.ico") if err != nil { w.WriteHeader(http.StatusInternalServerError) return diff --git a/pkg/client/handlers_gui.go b/pkg/client/handlers_gui.go index 0b4155623..a587f9738 100644 --- a/pkg/client/handlers_gui.go +++ b/pkg/client/handlers_gui.go @@ -841,7 +841,7 @@ func (c *Client) handleStaticAssets(response http.ResponseWriter, request *http. } func (c *Client) handleInternalAsset(response http.ResponseWriter, request *http.Request) { - data, err := bindata.Asset(request.URL.Path[1:]) + data, err := bindata.Files.ReadFile(request.URL.Path[1:]) if err != nil { http.Error(response, err.Error(), http.StatusNotFound) return diff --git a/pkg/client/html_templates.go b/pkg/client/html_templates.go index d03739851..ecf42df24 100644 --- a/pkg/client/html_templates.go +++ b/pkg/client/html_templates.go @@ -329,22 +329,45 @@ func since(t time.Time) string { return strings.ReplaceAll(durafmt.Parse(time.Since(t)).LimitFirstN(3).Format(mnd.DurafmtShort), " ", "") } +func (c *Client) parseTemplatesDirectory(filePath string) error { + items, err := bindata.Templates.ReadDir(filePath) + if err != nil { + return fmt.Errorf("failed reading internal templates: %w", err) + } + + for _, entry := range items { + filePath := path.Join(filePath, entry.Name()) + + if entry.IsDir() { // Recursion. + if err := c.parseTemplatesDirectory(filePath); err != nil { + return err + } + + continue + } + + data, err := bindata.Templates.ReadFile(filePath) + if err != nil { + return fmt.Errorf("failed reading internal template %s: %w", filePath, err) + } + + filePath = strings.TrimPrefix(filePath, "templates/") // no leading junk. + if c.template, err = c.template.New(filePath).Parse(string(data)); err != nil { + return fmt.Errorf("bug parsing internal template: %w", err) + } + } + + return nil +} + // ParseGUITemplates parses the baked-in templates, and overrides them if a template directory is provided. func (c *Client) ParseGUITemplates() error { // Index and 404 do not have template files, but they can be customized. index := "

" + c.Flags.Name() + `: working

` c.template = template.Must(template.New("index.html").Parse(index)).Funcs(c.getFuncMap()) - var err error - - // Parse all our compiled-in templates. - for _, name := range bindata.AssetNames() { - if strings.HasPrefix(name, "templates/") { - trim := strings.TrimPrefix(name, "templates/") - if c.template, err = c.template.New(trim).Parse(bindata.MustAssetString(name)); err != nil { - return fmt.Errorf("bug parsing internal template: %w", err) - } - } + if err := c.parseTemplatesDirectory("templates"); err != nil { + return err } if c.Flags.Assets != "" { diff --git a/pkg/client/tray.go b/pkg/client/tray.go index 70bbf22c5..f30dddc09 100644 --- a/pkg/client/tray.go +++ b/pkg/client/tray.go @@ -33,7 +33,7 @@ func (c *Client) startTray(ctx context.Context, clientInfo *clientinfo.ClientInf defer os.Exit(0) defer c.CapturePanic() - b, _ := bindata.Asset(ui.SystrayIcon) + b, _ := bindata.Files.ReadFile(ui.SystrayIcon) systray.SetTemplateIcon(b, b) systray.SetTooltip(mnd.PrintVersionInfo(c.Flags.Name())) // systray.SetOnClick(c.showMenu) // buggy diff --git a/pkg/ui/ui.go b/pkg/ui/ui.go index 7351f4609..3fdc52282 100644 --- a/pkg/ui/ui.go +++ b/pkg/ui/ui.go @@ -40,7 +40,7 @@ func GetPNG() string { } } - data, err := bindata.Asset("files/images/favicon.png") + data, err := bindata.Files.ReadFile("files/images/favicon.png") if err != nil { return "" }