Skip to content

Commit c021cba

Browse files
committed
address go lint checks
``` Error: fedoracoreos/fcos.go:39:17: Error return value of `resp.Body.Close` is not checked (errcheck) resp.Body.Close() ^ Error: stream/artifact_utils.go:22:23: Error return value of `resp.Body.Close` is not checked (errcheck) defer resp.Body.Close() ^ Error: example/example.go:28:10: ST1005: error strings should not be capitalized (staticcheck) return fmt.Errorf("Failed to download %s: %w", iso.Location, err) ^ Error: example/example.go:38:10: ST1005: error strings should not be capitalized (staticcheck) return fmt.Errorf("No %s architecture in stream", targetArch) ^ Error: example/example.go:42:10: ST1005: error strings should not be capitalized (staticcheck) return fmt.Errorf("No %s AWS images in stream", targetArch) ^ Error: example/example.go:62:2: QF1003: could use tagged switch on arg (staticcheck) if arg == "aws-ami" { ^ ```
1 parent 0ea89e3 commit c021cba

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

example/example.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func downloadISO(fcosstable stream.Stream) error {
2525
fmt.Printf("Downloading %s\n", iso.Location)
2626
path, err := iso.Download(".")
2727
if err != nil {
28-
return fmt.Errorf("Failed to download %s: %w", iso.Location, err)
28+
return fmt.Errorf("failed to download %s: %w", iso.Location, err)
2929
}
3030
fmt.Printf("Downloaded %s\n", path)
3131

@@ -35,15 +35,15 @@ func downloadISO(fcosstable stream.Stream) error {
3535
func printAMI(fcosstable stream.Stream) error {
3636
arch, ok := fcosstable.Architectures[targetArch]
3737
if !ok {
38-
return fmt.Errorf("No %s architecture in stream", targetArch)
38+
return fmt.Errorf("no %s architecture in stream", targetArch)
3939
}
4040
awsimages := arch.Images.Aws
4141
if awsimages == nil {
42-
return fmt.Errorf("No %s AWS images in stream", targetArch)
42+
return fmt.Errorf("no %s AWS images in stream", targetArch)
4343
}
4444
var regionVal stream.SingleImage
4545
if regionVal, ok = awsimages.Regions[region]; !ok {
46-
return fmt.Errorf("No %s AWS images in region %s", targetArch, region)
46+
return fmt.Errorf("no %s AWS images in region %s", targetArch, region)
4747
}
4848
fmt.Printf("%s\n", regionVal.Image)
4949

@@ -59,11 +59,12 @@ func run() error {
5959
if err != nil {
6060
return err
6161
}
62-
if arg == "aws-ami" {
62+
switch arg {
63+
case "aws-ami":
6364
return printAMI(*fcosstable)
64-
} else if arg == "download-iso" {
65+
case "download-iso":
6566
return downloadISO(*fcosstable)
66-
} else {
67+
default:
6768
return fmt.Errorf("invalid operation %s", arg)
6869
}
6970
}

fedoracoreos/fcos.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ func getStream(u url.URL) (*stream.Stream, error) {
3636
return nil, err
3737
}
3838
body, err := io.ReadAll(resp.Body)
39-
resp.Body.Close()
39+
if err != nil {
40+
return nil, err
41+
}
42+
err = resp.Body.Close()
4043
if err != nil {
4144
return nil, err
4245
}

stream/artifact_utils.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package stream
22

33
import (
44
"crypto/sha256"
5+
"errors"
56
"fmt"
67
"io"
78
"net/http"
@@ -19,7 +20,9 @@ func (a *Artifact) Fetch(w io.Writer) error {
1920
if err != nil {
2021
return err
2122
}
22-
defer resp.Body.Close()
23+
defer func() {
24+
err = errors.Join(resp.Body.Close())
25+
}()
2326

2427
if resp.StatusCode != http.StatusOK {
2528
return fmt.Errorf("%s returned status: %s", a.Location, resp.Status)

0 commit comments

Comments
 (0)