diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-04-25 15:15:52 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-04-26 18:12:22 +0200 |
commit | 51fbf3da9ee34a8143df5baeda6032c1747446d2 (patch) | |
tree | f5edbd047f5e4aea72b710403a0aa208b238c83b /pkg/bindings/images | |
parent | 216d9243077f478a9c7ffda1c6e0b1fcbad9ee76 (diff) | |
download | podman-51fbf3da9ee34a8143df5baeda6032c1747446d2.tar.gz podman-51fbf3da9ee34a8143df5baeda6032c1747446d2.tar.bz2 podman-51fbf3da9ee34a8143df5baeda6032c1747446d2.zip |
enable gocritic linter
The linter ensures a common code style.
- use switch/case instead of else if
- use if instead of switch/case for single case statement
- add space between comment and text
- detect the use of defer with os.Exit()
- use short form var += "..." instead of var = var + "..."
- detect problems with append()
```
newSlice := append(orgSlice, val)
```
This could lead to nasty bugs because the orgSlice will be changed in
place if it has enough capacity too hold the new elements. Thus we
newSlice might not be a copy.
Of course most of the changes are just cosmetic and do not cause any
logic errors but I think it is a good idea to enforce a common style.
This should help maintainability.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'pkg/bindings/images')
-rw-r--r-- | pkg/bindings/images/build.go | 16 | ||||
-rw-r--r-- | pkg/bindings/images/types.go | 2 |
2 files changed, 8 insertions, 10 deletions
diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index 1729bd922..9e0a0d798 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -225,10 +225,8 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO platform = "linux" } platform += "/" + options.Architecture - } else { - if len(platform) > 0 { - platform += "/" + runtime.GOARCH - } + } else if len(platform) > 0 { + platform += "/" + runtime.GOARCH } if len(platform) > 0 { params.Set("platform", platform) @@ -447,7 +445,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO } } } - secretsForRemote = append(secretsForRemote, strings.Join(modifiedOpt[:], ",")) + secretsForRemote = append(secretsForRemote, strings.Join(modifiedOpt, ",")) } } @@ -603,8 +601,8 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { // are required to visit all files. :( return nil } - - if d.Type().IsRegular() { // add file item + switch { + case d.Type().IsRegular(): // add file item info, err := d.Info() if err != nil { return err @@ -644,7 +642,7 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { seen[di] = name } return err - } else if d.IsDir() { // add folders + case d.IsDir(): // add folders info, err := d.Info() if err != nil { return err @@ -658,7 +656,7 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { if lerr := tw.WriteHeader(hdr); lerr != nil { return lerr } - } else if d.Type()&os.ModeSymlink != 0 { // add symlinks as it, not content + case d.Type()&os.ModeSymlink != 0: // add symlinks as it, not content link, err := os.Readlink(path) if err != nil { return err diff --git a/pkg/bindings/images/types.go b/pkg/bindings/images/types.go index 75cb38a0a..8e5e7ee92 100644 --- a/pkg/bindings/images/types.go +++ b/pkg/bindings/images/types.go @@ -177,7 +177,7 @@ type PullOptions struct { Variant *string } -//BuildOptions are optional options for building images +// BuildOptions are optional options for building images type BuildOptions struct { buildahDefine.BuildOptions } |