Skip to content

Commit

Permalink
Fix fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
nickschuch committed Sep 25, 2023
1 parent b6cc417 commit daa0c21
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Lint

on:
push

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.21'
- uses: golangci/golangci-lint-action@v3
with:
args: --timeout=5m
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Test

on:
push

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.21'
- run: go test ./...
26 changes: 18 additions & 8 deletions internal/scrape/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package scrape

import (
"encoding/base64"
"log"
"fmt"
"log"
"net/url"
"strings"

Expand Down Expand Up @@ -52,9 +52,9 @@ func Images(source *url.URL, user, pass string) ([]*url.URL, error) {
var originals []*url.URL

for _, image := range images {
original, err := getOriginalFromStyle(image)
if err != nil {
log.Println(err)
original, ok := getOriginalFromStyle(image)
if !ok {
continue
}

originals = append(originals, original)
Expand Down Expand Up @@ -84,17 +84,27 @@ func splitSrcSet(source *url.URL, set string) ([]*url.URL, error) {
return images, nil
}

func getOriginalFromStyle(link *url.URL) (*url.URL, error) {
// Helper function to get the original image from a style.
func getOriginalFromStyle(link *url.URL) (*url.URL, bool) {
if !strings.Contains(link.Path, "styles") {
return nil, false
}

split := strings.Split(link.Path, "/")

if len(split) < 7 {
return nil, false
}

newPath := append(split[:4], split[7:]...)

original := &url.URL{
Scheme: link.Scheme,
Host: link.Host,
Path: strings.Join(newPath, "/"),
Host: link.Host,
Path: strings.Join(newPath, "/"),
}

return original, nil
return original, true
}

func basicAuth(username, password string) string {
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"net/url"

kingpin "github.com/alecthomas/kingpin/v2"
"github.com/alecthomas/kingpin/v2"
"golang.org/x/sync/errgroup"

"github.com/previousnext/imaginator/internal/fileutils"
Expand Down Expand Up @@ -48,7 +48,7 @@ func run(source, user, pass, target string) error {

err := fileutils.Download(image.String(), user, pass, target)
if err != nil {
fmt.Printf("Failed to download: %w\n", err)
fmt.Errorf("Failed to download: %w\n", err)

Check failure on line 51 in main.go

View workflow job for this annotation

GitHub Actions / lint

unusedresult: result of fmt.Errorf call not used (govet)
}

return nil
Expand Down

0 comments on commit daa0c21

Please sign in to comment.