Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Jul 24, 2024
2 parents 639109c + cb6be3d commit 8d26593
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 52 deletions.
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 #####
Expand Down
3 changes: 1 addition & 2 deletions init/docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down
3 changes: 1 addition & 2 deletions init/docker/Dockerfile.cuda
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down
3 changes: 1 addition & 2 deletions init/docker/Dockerfile.scratch
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion pkg/bindata/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
api_docs.go
bindata.go
14 changes: 1 addition & 13 deletions pkg/bindata/README.md
Original file line number Diff line number Diff line change
@@ -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.**
- **Do not put anything except Go HTML template files in the templates/ directory.**
13 changes: 13 additions & 0 deletions pkg/bindata/bindata.go
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 1 addition & 1 deletion pkg/bindata/docs/generate.go
Original file line number Diff line number Diff line change
@@ -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 .
9 changes: 0 additions & 9 deletions pkg/bindata/generate.go

This file was deleted.

2 changes: 0 additions & 2 deletions pkg/bindata/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
2 changes: 1 addition & 1 deletion pkg/client/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/client/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/handlers_gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 33 additions & 10 deletions pkg/client/html_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := "<p>" + c.Flags.Name() + `: <strong>working</strong></p>`
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 != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand Down

0 comments on commit 8d26593

Please sign in to comment.