From 3bddeebf930efb872b99966df5553e0baf81834a Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 11 Feb 2021 14:15:26 +0100 Subject: Enable stylecheck linter Use the stylecheck linter and fix the reported problems. [NO TESTS NEEDED] Signed-off-by: Paul Holzinger Signed-off-by: Matthew Heon --- .golangci.yml | 1 - cmd/podman/images/search.go | 10 +++++----- libpod/boltdb_state.go | 6 +++--- libpod/container_exec.go | 2 ++ libpod/container_internal_linux.go | 6 +++--- libpod/container_path_resolution.go | 8 ++++---- pkg/api/handlers/compat/networks.go | 4 ++-- pkg/bindings/containers/containers.go | 4 ++-- pkg/bindings/errors.go | 6 +++--- pkg/bindings/network/network.go | 8 ++++---- pkg/domain/entities/network.go | 1 + pkg/rootless/rootless.go | 16 ++++++++-------- pkg/util/utils.go | 4 ++-- 13 files changed, 39 insertions(+), 37 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 6e46d55cd..85b753ad3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,7 +20,6 @@ linters: # All these break for one reason or another - nolintlint - gocognit - - stylecheck - testpackage - goerr113 - exhaustivestruct diff --git a/cmd/podman/images/search.go b/cmd/podman/images/search.go index c8ea4b04a..b8274cfce 100644 --- a/cmd/podman/images/search.go +++ b/cmd/podman/images/search.go @@ -156,12 +156,12 @@ func imageSearch(cmd *cobra.Command, args []string) error { return errors.Errorf("filters are not applicable to list tags result") } if report.IsJSON(searchOptions.Format) { - listTagsEntries := buildListTagsJson(searchReport) - return printJson(listTagsEntries) + listTagsEntries := buildListTagsJSON(searchReport) + return printArbitraryJSON(listTagsEntries) } row = "{{.Name}}\t{{.Tag}}\n" case report.IsJSON(searchOptions.Format): - return printJson(searchReport) + return printArbitraryJSON(searchReport) case cmd.Flags().Changed("format"): renderHeaders = parse.HasTable(searchOptions.Format) row = report.NormalizeFormat(searchOptions.Format) @@ -186,7 +186,7 @@ func imageSearch(cmd *cobra.Command, args []string) error { return tmpl.Execute(w, searchReport) } -func printJson(v interface{}) error { +func printArbitraryJSON(v interface{}) error { prettyJSON, err := json.MarshalIndent(v, "", " ") if err != nil { return err @@ -195,7 +195,7 @@ func printJson(v interface{}) error { return nil } -func buildListTagsJson(searchReport []entities.ImageSearchReport) []listEntryTag { +func buildListTagsJSON(searchReport []entities.ImageSearchReport) []listEntryTag { entries := []listEntryTag{} ReportLoop: diff --git a/libpod/boltdb_state.go b/libpod/boltdb_state.go index b2ee63b08..df00a8851 100644 --- a/libpod/boltdb_state.go +++ b/libpod/boltdb_state.go @@ -269,9 +269,9 @@ func (s *BoltState) Refresh() error { if err != nil { return err } - for _, execId := range toRemove { - if err := ctrExecBkt.Delete([]byte(execId)); err != nil { - return errors.Wrapf(err, "error removing exec session %s from container %s", execId, string(id)) + for _, execID := range toRemove { + if err := ctrExecBkt.Delete([]byte(execID)); err != nil { + return errors.Wrapf(err, "error removing exec session %s from container %s", execID, string(id)) } } } diff --git a/libpod/container_exec.go b/libpod/container_exec.go index 5aee847e1..443d631db 100644 --- a/libpod/container_exec.go +++ b/libpod/container_exec.go @@ -78,9 +78,11 @@ type ExecConfig struct { type ExecSession struct { // Id is the ID of the exec session. // Named somewhat strangely to not conflict with ID(). + // nolint:stylecheck Id string `json:"id"` // ContainerId is the ID of the container this exec session belongs to. // Named somewhat strangely to not conflict with ContainerID(). + // nolint:stylecheck ContainerId string `json:"containerId"` // State is the state of the exec session. diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index a45eae45f..9f4c2b81b 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -528,14 +528,14 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) { }} } for _, gid := range execUser.Sgids { - isGidAvailable := false + isGIDAvailable := false for _, m := range gidMappings { if gid >= m.ContainerID && gid < m.ContainerID+m.Size { - isGidAvailable = true + isGIDAvailable = true break } } - if isGidAvailable { + if isGIDAvailable { g.AddProcessAdditionalGid(uint32(gid)) } else { logrus.Warnf("additional gid=%d is not present in the user namespace, skip setting it", gid) diff --git a/libpod/container_path_resolution.go b/libpod/container_path_resolution.go index 805b3b947..51e3844c8 100644 --- a/libpod/container_path_resolution.go +++ b/libpod/container_path_resolution.go @@ -18,7 +18,7 @@ import ( // mountPoint (e.g., via a mount or volume), the resolved root (e.g., container // mount, bind mount or volume) and the resolved path on the root (absolute to // the host). -func (container *Container) resolvePath(mountPoint string, containerPath string) (string, string, error) { +func (c *Container) resolvePath(mountPoint string, containerPath string) (string, string, error) { // Let's first make sure we have a path relative to the mount point. pathRelativeToContainerMountPoint := containerPath if !filepath.IsAbs(containerPath) { @@ -26,7 +26,7 @@ func (container *Container) resolvePath(mountPoint string, containerPath string) // container's working dir. To be extra careful, let's first // join the working dir with "/", and the add the containerPath // to it. - pathRelativeToContainerMountPoint = filepath.Join(filepath.Join("/", container.WorkingDir()), containerPath) + pathRelativeToContainerMountPoint = filepath.Join(filepath.Join("/", c.WorkingDir()), containerPath) } resolvedPathOnTheContainerMountPoint := filepath.Join(mountPoint, pathRelativeToContainerMountPoint) pathRelativeToContainerMountPoint = strings.TrimPrefix(pathRelativeToContainerMountPoint, mountPoint) @@ -43,7 +43,7 @@ func (container *Container) resolvePath(mountPoint string, containerPath string) searchPath := pathRelativeToContainerMountPoint for { - volume, err := findVolume(container, searchPath) + volume, err := findVolume(c, searchPath) if err != nil { return "", "", err } @@ -74,7 +74,7 @@ func (container *Container) resolvePath(mountPoint string, containerPath string) return mountPoint, absolutePathOnTheVolumeMount, nil } - if mount := findBindMount(container, searchPath); mount != nil { + if mount := findBindMount(c, searchPath); mount != nil { logrus.Debugf("Container path %q resolved to bind mount %q:%q on path %q", containerPath, mount.Source, mount.Destination, searchPath) // We found a matching bind mount for searchPath. We // now need to first find the relative path of our diff --git a/pkg/api/handlers/compat/networks.go b/pkg/api/handlers/compat/networks.go index f0b922885..95cb06189 100644 --- a/pkg/api/handlers/compat/networks.go +++ b/pkg/api/handlers/compat/networks.go @@ -277,10 +277,10 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) { return } body := struct { - Id string + ID string `json:"Id"` Warning []string }{ - Id: net.ID, + ID: net.ID, } utils.WriteResponse(w, http.StatusCreated, body) } diff --git a/pkg/bindings/containers/containers.go b/pkg/bindings/containers/containers.go index 8e644b712..0a180c73d 100644 --- a/pkg/bindings/containers/containers.go +++ b/pkg/bindings/containers/containers.go @@ -270,8 +270,8 @@ func Top(ctx context.Context, nameOrID string, options *TopOptions) ([]string, e } params := url.Values{} if options.Changed("Descriptors") { - ps_args := strings.Join(options.GetDescriptors(), ",") - params.Add("ps_args", ps_args) + psArgs := strings.Join(options.GetDescriptors(), ",") + params.Add("ps_args", psArgs) } response, err := conn.DoRequest(nil, http.MethodGet, "/containers/%s/top", params, nil, nameOrID) if err != nil { diff --git a/pkg/bindings/errors.go b/pkg/bindings/errors.go index e75ce898d..51ea487be 100644 --- a/pkg/bindings/errors.go +++ b/pkg/bindings/errors.go @@ -20,12 +20,12 @@ func handleError(data []byte) error { return e } -func (a APIResponse) Process(unmarshalInto interface{}) error { - data, err := ioutil.ReadAll(a.Response.Body) +func (h APIResponse) Process(unmarshalInto interface{}) error { + data, err := ioutil.ReadAll(h.Response.Body) if err != nil { return errors.Wrap(err, "unable to process API response") } - if a.IsSuccess() || a.IsRedirection() { + if h.IsSuccess() || h.IsRedirection() { if unmarshalInto != nil { return json.Unmarshal(data, unmarshalInto) } diff --git a/pkg/bindings/network/network.go b/pkg/bindings/network/network.go index 7cd251b0e..d747f9bd7 100644 --- a/pkg/bindings/network/network.go +++ b/pkg/bindings/network/network.go @@ -102,7 +102,7 @@ func List(ctx context.Context, options *ListOptions) ([]*entities.NetworkListRep } // Disconnect removes a container from a given network -func Disconnect(ctx context.Context, networkName string, ContainerNameOrId string, options *DisconnectOptions) error { +func Disconnect(ctx context.Context, networkName string, ContainerNameOrID string, options *DisconnectOptions) error { if options == nil { options = new(DisconnectOptions) } @@ -117,7 +117,7 @@ func Disconnect(ctx context.Context, networkName string, ContainerNameOrId strin Container string Force bool }{ - Container: ContainerNameOrId, + Container: ContainerNameOrID, } if force := options.GetForce(); options.Changed("Force") { disconnect.Force = force @@ -136,7 +136,7 @@ func Disconnect(ctx context.Context, networkName string, ContainerNameOrId strin } // Connect adds a container to a network -func Connect(ctx context.Context, networkName string, ContainerNameOrId string, options *ConnectOptions) error { +func Connect(ctx context.Context, networkName string, ContainerNameOrID string, options *ConnectOptions) error { if options == nil { options = new(ConnectOptions) } @@ -151,7 +151,7 @@ func Connect(ctx context.Context, networkName string, ContainerNameOrId string, Container string Aliases []string }{ - Container: ContainerNameOrId, + Container: ContainerNameOrID, } if aliases := options.GetAliases(); options.Changed("Aliases") { connect.Aliases = aliases diff --git a/pkg/domain/entities/network.go b/pkg/domain/entities/network.go index b76bfcac7..b41a9997e 100644 --- a/pkg/domain/entities/network.go +++ b/pkg/domain/entities/network.go @@ -31,6 +31,7 @@ type NetworkReloadOptions struct { // NetworkReloadReport describes the results of reloading a container network. type NetworkReloadReport struct { + // nolint:stylecheck Id string Err error } diff --git a/pkg/rootless/rootless.go b/pkg/rootless/rootless.go index df35c0d6b..b5538efc3 100644 --- a/pkg/rootless/rootless.go +++ b/pkg/rootless/rootless.go @@ -61,9 +61,9 @@ var ( gidMapOnce sync.Once ) -// GetAvailableUidMap returns the UID mappings in the +// GetAvailableUIDMap returns the UID mappings in the // current user namespace. -func GetAvailableUidMap() ([]user.IDMap, error) { +func GetAvailableUIDMap() ([]user.IDMap, error) { uidMapOnce.Do(func() { var err error uidMap, err = user.ParseIDMapFile("/proc/self/uid_map") @@ -75,9 +75,9 @@ func GetAvailableUidMap() ([]user.IDMap, error) { return uidMap, uidMapError } -// GetAvailableGidMap returns the GID mappings in the +// GetAvailableGIDMap returns the GID mappings in the // current user namespace. -func GetAvailableGidMap() ([]user.IDMap, error) { +func GetAvailableGIDMap() ([]user.IDMap, error) { gidMapOnce.Do(func() { var err error gidMap, err = user.ParseIDMapFile("/proc/self/gid_map") @@ -92,11 +92,11 @@ func GetAvailableGidMap() ([]user.IDMap, error) { // GetAvailableIDMaps returns the UID and GID mappings in the // current user namespace. func GetAvailableIDMaps() ([]user.IDMap, []user.IDMap, error) { - u, err := GetAvailableUidMap() + u, err := GetAvailableUIDMap() if err != nil { return nil, nil, err } - g, err := GetAvailableGidMap() + g, err := GetAvailableGIDMap() if err != nil { return nil, nil, err } @@ -114,7 +114,7 @@ func countAvailableIDs(mappings []user.IDMap) int64 { // GetAvailableUids returns how many UIDs are available in the // current user namespace. func GetAvailableUids() (int64, error) { - uids, err := GetAvailableUidMap() + uids, err := GetAvailableUIDMap() if err != nil { return -1, err } @@ -125,7 +125,7 @@ func GetAvailableUids() (int64, error) { // GetAvailableGids returns how many GIDs are available in the // current user namespace. func GetAvailableGids() (int64, error) { - gids, err := GetAvailableGidMap() + gids, err := GetAvailableGIDMap() if err != nil { return -1, err } diff --git a/pkg/util/utils.go b/pkg/util/utils.go index e0f631eb4..901a482f6 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -530,9 +530,9 @@ func ParseInputTime(inputTime string) (time.Time, error) { } } - unix_timestamp, err := strconv.ParseInt(inputTime, 10, 64) + unixTimestamp, err := strconv.ParseInt(inputTime, 10, 64) if err == nil { - return time.Unix(unix_timestamp, 0), nil + return time.Unix(unixTimestamp, 0), nil } // input might be a duration -- cgit v1.2.3-54-g00ecf