Skip to content

Commit

Permalink
Merge branch 'dn2_bindata' into unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Jul 19, 2024
2 parents 73b6a4d + 0e1354a commit e369904
Show file tree
Hide file tree
Showing 15 changed files with 48 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 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
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.**
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"
)
3 changes: 2 additions & 1 deletion pkg/client/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,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")
file, _ := bindata.Files.ReadFile("other/fortunes.txt")
fortunes := strings.Split(string(file), "\n%\n")
return fortunes[rand.Intn(len(fortunes))] //nolint:gosec
}
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 @@ -849,7 +849,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 @@ -328,22 +328,45 @@ func since(t time.Time) string {
return strings.ReplaceAll(durafmt.Parse(time.Since(t)).LimitFirstN(3).Format(mnd.DurafmtShort), " ", "")
}

const templates = "templates/"

func (c *Client) parseTemplatesDirectory(filePath string) error {
items, err := bindata.Templates.ReadDir(strings.TrimSuffix(filePath, "/"))
if err != nil {
return fmt.Errorf("failed reading internal templates: %w", err)
}

for _, entry := range items {
if entry.IsDir() {
if err := c.parseTemplatesDirectory(filepath.Join(filePath, entry.Name())); err != nil {
return err
}

continue
}

data, err := bindata.Templates.ReadFile(filepath.Join(filePath, entry.Name()))
if err != nil {
return fmt.Errorf("failed reading internal template %s: %w", entry.Name(), err)
}

filePath = strings.TrimPrefix(filepath.Join(filePath, entry.Name()), templates)
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_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func getPNG() string {
return try
}
data, err := bindata.Asset("files/favicon.png")
data, err := bindata.Files.ReadFile("files/favicon.png")
if err != nil {
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/ui_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func getPNG() string {
return ""
}

data, err := bindata.Asset("files/favicon.png")
data, err := bindata.Files.ReadFile("files/favicon.png")
if err != nil {
return ""
}
Expand Down

0 comments on commit e369904

Please sign in to comment.