From 47b8e7a79813c430388eb16885fa3f324fad19e0 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Sun, 22 Dec 2024 03:34:38 +0100 Subject: [PATCH] fix lint issues --- cmd/main.go | 2 +- internal/app/undock.go | 4 ++-- pkg/extractor/blob.go | 3 +-- pkg/extractor/image/image.go | 10 +++++----- pkg/image/ref.go | 6 ++---- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 801bd531..50fb3463 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -33,7 +33,7 @@ func main() { runtime.GOMAXPROCS(runtime.NumCPU()) meta.Version = version - meta.UserAgent = fmt.Sprintf("%s/%s go/%s %s", meta.ID, meta.Version, runtime.Version()[2:], strings.Title(runtime.GOOS)) + meta.UserAgent = fmt.Sprintf("%s/%s go/%s %s", meta.ID, meta.Version, runtime.Version()[2:], strings.Title(runtime.GOOS)) //nolint:staticcheck // ignoring "SA1019: strings.Title is deprecated", as for our use we don't need full unicode support _ = kong.Parse(&cli, kong.Name(meta.ID), diff --git a/internal/app/undock.go b/internal/app/undock.go index 167f0b89..fed89deb 100644 --- a/internal/app/undock.go +++ b/internal/app/undock.go @@ -9,7 +9,7 @@ import ( "github.com/crazy-max/undock/internal/config" ximage "github.com/crazy-max/undock/pkg/extractor/image" "github.com/crazy-max/undock/pkg/image" - specs "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" ) @@ -18,7 +18,7 @@ type Undock struct { ctx context.Context meta config.Meta cli config.Cli - platform specs.Platform + platform ocispecs.Platform } // New creates new undock instance diff --git a/pkg/extractor/blob.go b/pkg/extractor/blob.go index 9df8aa45..f80fe576 100644 --- a/pkg/extractor/blob.go +++ b/pkg/extractor/blob.go @@ -2,7 +2,6 @@ package extractor import ( "context" - "fmt" "io" "io/fs" "os" @@ -93,7 +92,7 @@ func ExtractBlob(filename string, dest string, opts ExtractBlobOpts) error { case f.FileInfo.Mode()&fs.ModeSymlink != 0: return writeSymlink(ctx, path, f) default: - return fmt.Errorf("cannot handle file mode: %v", f.FileInfo.Mode()) + return errors.Errorf("cannot handle file mode: %v", f.FileInfo.Mode()) } }) } diff --git a/pkg/extractor/image/image.go b/pkg/extractor/image/image.go index fe5dc0b6..0085d1c4 100644 --- a/pkg/extractor/image/image.go +++ b/pkg/extractor/image/image.go @@ -11,7 +11,7 @@ import ( "github.com/containerd/containerd/platforms" "github.com/containers/image/v5/manifest" "github.com/crazy-max/undock/pkg/extractor" - specs "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" "github.com/rs/zerolog" "github.com/rs/zerolog/log" @@ -31,7 +31,7 @@ type Options struct { // Source image reference Source string // Platform to enforce for Source image - Platform specs.Platform + Platform ocispecs.Platform // Includes a subset of files/dirs from the Source image Includes []string // All extracts all architectures if Source image is a manifest list @@ -102,14 +102,14 @@ func (c *Client) Extract() error { } type manifestEntry struct { - platform specs.Platform + platform ocispecs.Platform manifest *manifest.OCI1 } var mans []manifestEntry mtype := manifest.GuessMIMEType(manblob) - if mtype == specs.MediaTypeImageManifest { + if mtype == ocispecs.MediaTypeImageManifest { man, err := manifest.OCI1FromManifest(manblob) if err != nil { return errors.Wrap(err, "cannot create OCI manifest instance from blob") @@ -118,7 +118,7 @@ func (c *Client) Extract() error { platform: c.opts.Platform, manifest: man, }) - } else if mtype == specs.MediaTypeImageIndex { + } else if mtype == ocispecs.MediaTypeImageIndex { ocindex, err := manifest.OCI1IndexFromManifest(manblob) if err != nil { return errors.Wrap(err, "cannot create OCI manifest index instance from blob") diff --git a/pkg/image/ref.go b/pkg/image/ref.go index b67205c7..8314da8b 100644 --- a/pkg/image/ref.go +++ b/pkg/image/ref.go @@ -28,10 +28,8 @@ func Reference(name string) (reference.Named, error) { ref, err := reference.ParseNormalizedNamed(name) if err != nil { return nil, errors.Wrapf(err, "parsing normalized named %q", name) - } - - if _, ok := ref.(reference.Named); !ok { - return nil, fmt.Errorf("%q is not a named reference", name) + } else if ref == nil { + return nil, errors.Errorf("%q is not a named reference", name) } if _, hasTag := ref.(reference.NamedTagged); hasTag {